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

about WA3
Posted by abc 29 Sep 2010 20:03
anobody have any ideas ? i tested all from forum + generated, all are correct. code :

# include <iostream>

# include <vector>

# include <algorithm>

# include <cstdlib>

# include <string>

# include <map>

# include <climits>

# include <cmath>

# include <iomanip>
# include <queue>
# include <sstream>





# define LOOP(i,s,e) for(int i=s; i<e; ++i)



using namespace std;


struct P
{
    int x,y;
    int t;
    P(int a, int b): x(a),y(b) {};
    P() { P(0,0); }
};

int ar[12][12] = {0};
queue<P> que;

void go(int x , int y, string ch)
{
    if(ar[x][y] == 1)
    {
        cout << ch;
        que.push( P(x,y) );
        ar[x][y] = 0;
    }
}

void first(int n)
{
    int a,b;

    if (n == 0) cout << ".";
    else if (n == 1)
    {
        cin >> a >> b;
        cout << a << " " << b << endl << ".";
    }
    else
    {

        LOOP(i,0,n)
        {
            cin >> a >> b;
            if (i == 0) que.push( P(b,a) );
            ar[b][a] = 1;
        }

        cout << que.front().y << " " << que.front().x << endl;
        ar[que.front().x][que.front().y] = 0;

        while(!que.empty() )
        {
            P t = que.front();
            que.pop();

            go(t.x, t.y+1, "R");
            go(t.x-1, t.y, "B");
            go(t.x, t.y-1, "L");
            go(t.x+1, t.y, "T");

            cout << (que.empty() ? ".":",") << endl;
        }
    }
}

bool cmp(const P& a, const P& b)
{
    if (a.x == b.x) return (a.y < b.y);
    else return (a.x < b.x);
}

void calcule(string tmp, queue<P>& que, vector<P>& vec)
{
    P t = que.front();
    que.pop();
    vec.push_back( P(t.y, t.x) );

    LOOP(i,0,tmp.size()-1)
    {

        if (tmp[i] == 'T')  que.push( P(t.x+1, t.y) );
        else if (tmp[i] == 'R')  que.push( P(t.x, t.y+1) );
        else if (tmp[i] == 'B')  que.push( P(t.x-1, t.y) );
        else if (tmp[i] == 'L')  que.push( P(t.x, t.y-1) );

       // cout << tmp[i] << endl;
      //  cout << que.back().x << " " << que.back().y << endl;
    }
}

void second(int a, int b)
{
    string tmp;
    que.push( P(a,b) );

    vector<P> vec;

    while (42)
    {
        getline(cin, tmp);
        calcule(tmp, que, vec );
        if (tmp.find('.', 0) != string::npos) break;
    }
    sort(vec.begin(), vec.end(), cmp);
    cout << vec.size() << endl;

    LOOP(i,0,vec.size())
    {
        cout << vec[i].x << " " << vec[i].y << endl;
    }
}


int main()

{
    string str;
    getline(cin, str);
    for (int i=str.size()-1; i>=0; --i)
    {
        if (str[i] == ' ') str.erase(str.begin() +i);
        else break;
    }

    istringstream st(str);
    if (str.find(' ', 0) == string::npos)
    {
        int n;
        st >> n;
        first(n);
    }
    else
    {
        int a,b;
        st >> a >> b;
        second(b,a);
    }


    exit(0);

}
Re: about WA3
Posted by abc 29 Sep 2010 20:05
code looks tedios, without Tab's and highlight especially
sorry :(