ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1008. Image Encoding

WA on test #2
Posted by frp 25 Feb 2010 22:57
Why I have wa #2?
My solution:
///////////////
#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;

#define mkpair make_pair

int main()
{
    int n,m;
    char a[300];
    cin.getline(a,300);
    int fmt=sscanf(a,"%d%d",&n,&m);
    bool fmt1;
    bool pic[10][10];
    bool pic2[10][10];
    int ml[10],md[10];
    if(fmt==1)fmt1=true;else fmt1=false;
    if(fmt1)
    {
        int i,j,x,y;
        for(i=0;i<10;i++)
            for(j=0;j<10;j++){pic[i][j]=false;pic2[i][j]=false;}
        for(i=0;i<10;i++){ml[i]=100;md[i]=100;}
        for(i=0;i<n;i++)
        {
            cin>>x>>y;
            x--;y--;
            pic[y][x]=true;
            if(ml[y]>x)ml[y]=x;
            if(md[x]>y)md[x]=y;
        }
        int mdl=100,mdd=-1;
        for(i=0;i<10;i++)
        {
            if(ml[i]<mdl)mdl=ml[i];
        }
        mdd=md[mdl];
        cout<<mdl+1<<" "<<mdd+1<<"\n";
        queue<pair<int,int> > pc;
        pc.push(mkpair(mdl,mdd));
        while(!pc.empty())
        {
            x=pc.front().first;y=pc.front().second;pc.pop();
            pic2[y][x]=true;
            if(x<9 && !pic2[y][x+1] && pic[y][x+1]){cout<<"R";pic2[y][x+1]=true;pc.push(mkpair(x+1,y));}
            if(y<9 && !pic2[y+1][x] && pic[y+1][x]){cout<<"T";pic2[y+1][x]=true;pc.push(mkpair(x,y+1));}
            if(x>0 && !pic2[y][x-1] && pic[y][x-1]){cout<<"L";pic2[y][x-1]=true;pc.push(mkpair(x-1,y));}
            if(y>0 && !pic2[y-1][x] && pic[y-1][x]){cout<<"B";pic2[y-1][x]=true;pc.push(mkpair(x,y-1));}
            if(pc.empty())cout<<".\n";else cout<<",\n";
        }
    }
    else
    {
        queue<pair<int,int> > pc;
        pc.push(mkpair(n-1,m-1));
        int i,j;
        for(i=0;i<10;i++)
            for(j=0;j<10;j++){pic[i][j]=false;pic2[i][j]=false;}
        int cnt=0;
        bool dr=true;
        while(!pc.empty())
        {
            cnt++;
            int y=pc.front().second,x=pc.front().first;pc.pop();
            pic[y][x]=true;
            char c='\0';
            while((c!=',')&&(c!='.')&&(dr))
            {
                cin>>c;
                switch(c)
                {
                    case 'R':pic[y][x+1]=true;
                        pc.push(mkpair(y,x+1));
                        break;
                    case 'T':pic[y+1][x]=true;
                        pc.push(mkpair(y+1,x));
                        break;
                    case 'L':pic[y][x-1]=true;
                        pc.push(mkpair(y,x-1));
                        break;
                    case 'B':pic[y-1][x]=true;
                        pc.push(mkpair(y-1,x));
                        break;
                }
                dr=(c!='.');
            }
        }
        int y,x;
        cout<<cnt<<'\n';
        for(x=0;x<10;x++)
            for(y=0;y<10;y++)
                if(pic[y][x])cout<<x+1<<' '<<y+1<<'\n';
    }
    return 0;
}
//////////////////////////