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

Help! Who can help me?Thank you! I always got wa1
Posted by guojinyu 16 Jul 2011 15:29
I have tested it for many times,but I still got wa1,please help me
this is my program:
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;
ifstream fin("1008.in");
ofstream fout("1008.out");
int n,c=1,sign=0,kong,sx,sy,ox=1;
string pan;
int bla[11][2],weiyi[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int dui[10000],flag[11];
int zhan[20][2],zuo=0,you=1;
char wei[4]={'R','T','L','B'};
int head=0,tail=1;
string ord[20];
void init()
{
  stringstream sn;
  int i;
  sn<<pan;
  sn>>n;
  for(i=1;i<=n;i++)
    fin>>bla[i][0]>>bla[i][1];
}
void solve()
{
  int fang,x,y,i;
  fout<<bla[1][0]<<' '<<bla[1][1]<<endl;
  dui[head]=1;
  while(head<tail)
  {
    flag[dui[head]]=1;
    for(fang=0;fang<4;fang++)
    {
      x=bla[dui[head]][0]+weiyi[fang][0];
      y=bla[dui[head]][1]+weiyi[fang][1];
      for(i=1;i<=n;i++)
        if(flag[i]==0)
          if(bla[i][0]==x&&bla[i][1]==y)
          {
            dui[tail]=i;
                  flag[i]=1;
            tail++;
            fout<<wei[fang];
                  break;
          }
    }
    head++;
    if(c==n)
      fout<<'.'<<endl;
    else
      {
      fout<<','<<endl;
        c++;
      }
  }
}
void init1()
{
  string fir,sec;
  stringstream fs,ss;
  fir=pan.substr(0,kong);
  fs<<fir;
  fs>>sx;
  sec=pan.substr(kong+1,pan.length()-kong-1);
  ss<<sec;
  ss>>sy;
  fin>>ord[1];
  while(ord[ox][ord[ox].length()-1]!='.')
    fin>>ord[++ox];
}
void solve1()
{
  int i,j;
  zhan[zuo][0]=sx;
  zhan[zuo][1]=sy;
  for(i=1;i<=ox;i++)
  {
      for(j=0;j<(ord[i].length()-1);j++)
      {
        zhan[you][0]=zhan[zuo][0];
        zhan[you][1]=zhan[zuo][1];
        if(ord[i][j]=='R')
            zhan[you][0]++;
        if(ord[i][j]=='L')
            zhan[you][0]--;
        if(ord[i][j]=='T')
            zhan[you][1]++;
        if(ord[i][j]=='B')
            zhan[you][1]--;
        you++;
      }
      zuo++;
  }
  for(i=0;i<you-1;i++)
      for(j=i+1;j<you;j++)
      {
        if(zhan[i][0]>zhan[j][0])
        {
            swap(zhan[i][0],zhan[j][0]);
            swap(zhan[i][1],zhan[j][1]);
        }
        if(zhan[i][0]==zhan[j][0]&&zhan[i][1]>zhan[j][1])
        {
            swap(zhan[i][0],zhan[j][0]);
            swap(zhan[i][1],zhan[j][1]);
        }
      }
  fout<<you<<endl;
  for(i=0;i<you;i++)
  {
    fout<<zhan[i][0]<<' '<<zhan[i][1];
    fout<<endl;
  }
}
int main()
{
  int i;
  getline(fin,pan);
  for(i=0;i<(pan.length());i++)
    if(pan[i]==' ')
    {
      kong=i;
      sign=1;
      break;
    }
  if(sign==0)
  {
    init();
    solve();
  }
  if(sign==1)
  {
      init1();
      solve1();
  }
  return(0);
}
Re: Help! Who can help me?Thank you! I always got wa1
Posted by Backone 16 Jul 2011 20:05
Bug is in array dimensions... too small.. check it. GL
Re: Help! Who can help me?Thank you! I always got wa1
Posted by guojinyu 26 Jul 2011 07:51
dimensions?Please tell me clearly,thank you!