Check if the order RTLB is respected and pay attention to the fact that the matrix in the problem is inversed in comparison to the one that you build i.e. the bottom is curr_row - 1 and top is curr_row + 1. It says we have to start at the lowest left tile. Does that mean that the euclidean distance of the tile from origin should be minimum?? or does it mean that we have to look for left most layer and lowest tile in that?? Input: 2 3 RT, RT, , B, , . Output: 6 2 3 2 4 3 3 3 4 4 2 4 3 using System; using System.Linq; using System.Collections.Generic; public class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int maxX = 0; int maxY = 0; int[,] str = new int[n,2]; for (int i = 0; i < n; i++) { string[] s = Console.ReadLine().Split(' '); str[i, 0] = int.Parse(s[0]); str[i, 1] = int.Parse(s[1]); if (str[i,0] > maxX) maxX = str[i,0]; if (str[i,1] > maxY) maxY = str[i,1]; } bool[,] ans = new bool[maxX+2, maxY+2]; for (int i = 0; i < n; i++) ans[str[i,0],str[i,1]]= true; List<string> pool = new List<string>(); pool.Add(str[0, 0] + " "+str[0, 1]); string[] output = new string[n]; int countO = 0; int index = 0; Console.WriteLine(pool.ElementAt(0)); while (index<pool.Count) { string[] point = pool.ElementAt(index).Split(' '); int x = int.Parse(point[0]); int y = int.Parse(point[1]); ans[x, y] = false; string search = ""; if (ans[x + 1, y]) { search += "R"; pool.Add((x + 1) + " " + y); ans[x+1, y] = false; } if (ans[x, y + 1]) { search += "T"; pool.Add(x + " " + (y+1)); ans[x, y+1] = false; } if (ans[x, y - 1]) { search += "B"; pool.Add(x + " " + (y-1)); ans[x, y-1] = false; } output[countO] = search; countO++; //Console.WriteLine("in {0}",pool.Count); index++; } for (int i = 0; i < n; i++) { Console.Write(output[i]); if (i < n - 1) Console.WriteLine(","); else Console.WriteLine("."); } } } program Project2; {$APPTYPE CONSOLE} uses SysUtils; var a:array [0..110,0..110] of integer; d:array [0..2000] of string; k:array[0..2000,1..2] of integer; x1,y1,x,y,i,sc,l,j,n,f,b1,c1:integer; puk:string; procedure ar (b,c,m:integer); var res:string; begin res:=''; k[m,1]:=b; k[m,2]:=c; if a[b+1,c]=1 then begin a[b+1,c]:=0; res:=res+'R' end; if a[b,c+1]=1 then begin a[b,c+1]:=0; res:=res+'T' end; if a[b-1,c]=1 then begin a[b-1,c]:=0; res:=res+'L' end; if a[b,c-1]=1 then begin a[b,c-1]:=0; res:=res+'B' end; d[m]:=res; end; begin readln (n); for i:= 0 to 11 do for j:= 0 to 11 do a[i,j]:=0; read (x1); readln (y1); a[x1,y1]:=0; writeln (x1,' ',y1); for i:= 2 to n do begin read (x); readln (y); a[x,y]:=1; end; f:=1; sc:=1; ar(x1,y1,f); repeat b1:=k[sc,1];c1:=k[sc,2]; puk:=d[sc]; l:=length(puk); if l>0 then for i:= 1 to l do begin case puk[i] of 'R': begin f:=f+1; ar(b1+1,c1,f); end; 'T': begin f:=f+1; ar(b1,c1+1,f); end; 'L': begin f:=f+1; ar(b1-1,c1,f); end; 'B': begin f:=f+1; ar(b1,c1-1,f); end; end; end; inc(sc) until sc=n; if f>1 then for i:= 1 to f-1 do writeln (d[i],','); writeln (d[f],'.') end. Program work ideally on my computer. If you are getting WA#1, try this. Input: 8 1 1 1 2 1 3 2 1 2 3 3 1 3 2 3 3 Output: 1 1 RT, R, T, T, R, T, , . The following code: cin>>n; for(i=1;i<=n;i++) { cin>>x[i]>>y[i]; assert(x[i]>=1 && x[i]<=10 && y[i]>=1 && y[i]<=10); here[x[i]][y[i]]=true; } gives RTE, so test 2 is wrong. After, removing the assert, it gives WA :) Input One representation of the image will be given to your program in the input. Output Your program has to write other representation of the image to the output. The following code: cin>>n; for(i=1;i<=n;i++) { cin>>x[i]>>y[i]; assert(x[i]>=1 && x[i]<=10 && y[i]>=1 && y[i]<=10); here[x[i]][y[i]]=true; } gives RTE, so test 2 is wrong. After, removing the assert, it gives WA :) TEST 2 like this : Input: 2 3 RT, RT, , B, , . Output: 6 2 3 2 4 3 3 3 4 4 2 4 3 Please someone tell me where is the wrong in my code. #include <iostream> #include <queue> #include <stdlib.h> #include <stdio.h> #include <string.h> using namespace std; struct dott{ int x; int y; }; int main() { char str[8]; gets(str); if(strlen(str) <= 2){ int a, b, n; n = atoi(str); bool XY[200][200]; memset(XY, 0, sizeof(XY)); struct dott center; cin>>a>>b; center.x = a; center.y = b; for(int i=2; i<=n; i++){ cin>>a>>b; XY[a][b] = 1; } queue<dott> qu; qu.push(center); cout<<center.x<<" "<<center.y<<"\n"; while(!qu.empty()){ dott pix = qu.front(); qu.pop(); if(XY[pix.x + 1][pix.y] == 1){ cout<<"R"; center.x = pix.x + 1; center.y = pix.y; qu.push(center); XY[pix.x + 1][pix.y] = 0; } if(XY[pix.x][pix.y + 1] == 1){ cout<<"T"; center.x = pix.x; center.y = pix.y + 1; qu.push(center); XY[pix.x][pix.y + 1] = 0; } if(XY[pix.x - 1][pix.y] == 1){ cout<<"L"; center.x = pix.x - 1; center.y = pix.y; qu.push(center); XY[pix.x - 1][pix.y] = 0; } if(XY[pix.x][pix.y - 1] == 1){ cout<<"B"; center.x = pix.x; center.y = pix.y - 1; qu.push(center); XY[pix.x][pix.y - 1] = 0; } if(!qu.empty()){ cout<<",\n"; } else{ cout<<"."; } } } else{ int a, b, count=0; bool XY[200][200]; memset(XY, 0, sizeof(XY)); struct dott centre; char *s; s = strtok(str," "); a = atoi(s); s = strtok(NULL," "); b = atoi(s); XY[a][b] = 1; centre.x = a; centre.y = b; queue<dott> qu; qu.push(centre); string str[200]; for(int i=0; ;i++){ cin>>str[i]; if(str[i] == "."){ break; } count++; } for(int i=0; i<count; i++){ dott S = qu.front(); qu.pop(); for(int j=0; j<str[i].size(); j++){ if(str[i][j] == 'R'){ XY[S.x+1][S.y] = 1; centre.x = S.x+1; centre.y = S.y; qu.push(centre); } if(str[i][j] == 'T'){ XY[S.x][S.y+1] = 1; centre.x = S.x; centre.y = S.y+1; qu.push(centre); } if(str[i][j] == 'L'){ XY[S.x-1][S.y] = 1; centre.x = S.x-1; centre.y = S.y; qu.push(centre); } if(str[i][j] == 'B'){ XY[S.x][S.y-1] = 1; centre.x = S.x; centre.x = S.y-1; qu.push(centre); } } } cout<<count+1<<"\n"; for(int i=0; i<100; i++){ for(int j=0; j<100; j++){ if(XY[i][j] == 1){ cout<<i<<" "<<j<<"\n"; } } } } return 0; } Edited by author 09.01.2017 17:37 Please someone tell me where maximum people make mistake in this problem. Or please provide some hints. #include<stdio.h> #include<string.h> char s[100]; bool map[200][200],bo; int n,m,x,y,xx,yy,a[11000],b[11000],c,zy; void find(int xx,int yy,int xy) { bool l,r,s,x; l=r=s=x=false; map[xx][yy]=false; if (map[xx+1][yy]) {printf("R");map[xx+1][yy]=false;c++;a[c]=xx+1;b[c]=yy;} if (map[xx][yy+1]) {printf("T");map[xx][yy+1]=false;c++;a[c]=xx;b[c]=yy+1;} if (map[xx-1][yy]) {printf("L");map[xx-1][yy]=false;c++;a[c]=xx-1;b[c]=yy;} if (map[xx][yy-1]) {printf("B");map[xx][yy-1]=false;c++;a[c]=xx;b[c]=yy-1;} if (xy==c) return; printf(",\n"); if (xy<c) find(a[xy+1],b[xy+1],xy+1);
} int main() { memset(map,false,sizeof(map)); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); gets(s); if (strlen(s)==1) { n=s[0]-48; for (int i=1;i<=n;i++) { scanf("%d%d",&x,&y); if (i==1) { xx=x; yy=y; } map[x][y]=true; } a[1]=xx; b[1]=xx; c=1; printf("%d %d\n",xx,yy); find(xx,yy,1); printf(".\n"); } else { x=s[0]-48; y=s[2]-48; map[x][y]=true; zy=1; c=1; while (true) { gets(s); if (s[0]=='.') break; for (int i=0;i<=strlen(s);i++) { if (s[i]=='R') { c++;a[c]=x+1;b[c]=y; map[x+1][y]=true; } else if (s[i]=='T') {map[x][y+1]=true;c++;a[c]=x;b[c]=y+1;} else if (s[i]=='L') {map[x-1][y]=true;c++;a[c]=x-1;b[c]=y;} else if (s[i]=='B') {map[x][y-1]=true;c++;a[c]=x;b[c]=y-1;} } zy++; x=a[zy]; y=b[zy]; } printf("%d\n",zy); for (int i=1;i<=10;i++) for (int j=1;j<=10;j++) if (map[i][j]) printf("%d %d\n",i,j); } } Edited by author 09.01.2017 16:46 I TLE on test 1. What is the test 1 Thank you. Тест №2 противоречит условию задачи , это тест такой : 1 1 0 (подобрал с помощью бинпоиска) These days I've noticed that some programmer got stuck on BIG problems like "ships version 2", which may cost up to tens of seconds to judge. However the general limit for submitting a solution is 10 second. So, you see a whole lot page of 'waiting'. Maybe increase the interval for these problems? I think it is bad idea to tighten rules because of one genius (who made about 1000 submissions on the problem in several hours) - better just to ban it. But, since it is easy to register again, a good idea for timus maybe to restrict the number of submissions of one user (or from one IP) during the last 24 hours (at most 100, for example). Edited by author 20.09.2013 02:27 Edited by author 20.09.2013 08:33 Sounds readonable. Let's see what the admin has to say lol Strange, string s = Console.ReadLine(); ===>AC string s = Console.ReadLine().Trim(); ===> Runtime Error (AV #2) string s = Console.ReadLine().TrimEnd(); ====> Same as above who can explain this? Console.ReadLine() == null at the end of file thanks... yes. it all makes sense now. Can not find mistake, it's crashing on 1 test. Can anybody help? Thnx. #include <map> #include <set> #include <deque> #include <stack> #include <queue> #include <cmath> #include <vector> #include <memory.h> #include <stdio.h> #include <fstream> #include <string> #include <iostream> #include <algorithm> using namespace std; #define sc scanf #define fi first #define exp 1e-10 #define se second #define pr printf #define exp 1e-15 #define ll long long #define mp make_pair #define pb push_back #define sqr(x) (x)*(x) #define N (int)(1e+3)*2 #define mod (int)(1e+9)+7 #define inf (int)INFINITY/4 #define in(s) freopen(s, "r", stdin); #define out(s) freopen(s, "w", stdout); int dp[20][20]; bool us[20][20]; vector <int> x, y; int main(){ int n, i, j, m, v, c; cin >> n; for(m = 1; m <= n; m++){ cin >> i >> j; dp[i][j] = 1; if(v == 0) v = i, c = j; }int k = 0; cout << v << ' ' << c << "\n"; x.pb(v); y.pb(c); while(!x.empty()){ v = x[0], c = y[0]; k++; if(!us[v][c]){ if(!us[v + 1][c] && dp[v + 1][c] == 1) dp[v + 1][c]++, cout << "R", x.pb(v + 1), y.pb(c); if(!us[v][c + 1] && dp[v][c + 1] == 1) dp[v][c + 1]++, cout << "T", x.pb(v), y.pb(c + 1); if(!us[v - 1][c] && dp[v - 1][c] == 1) dp[v - 1][c]++, cout << "L", x.pb(v - 1), y.pb(c); if(!us[v][c - 1] && dp[v][c - 1] == 1) dp[v][c - 1]++, cout << "B", x.pb(v), y.pb(c - 1); if(k < n) cout << ",\n"; else cout << ".\n"; } us[v][c] = true; x.erase(x.begin()); y.erase(y.begin()); } return 0; } Edited by author 15.03.2013 23:27 test 6 is something like this: 1 1 . answer: 1 1 1 I got TLE 15 times beacuse of this test! hi,friend how to get the damn test data i TLE on test 1 many time Thank you!! You've saved me. :) Sample Input: Sample Output: 6 2 3 2 3 RT, 2 4 RT, 3 3 , 3 4 B, 4 2 , 4 3 . I just wonder why there is only one comma on the end. It seems that there should be two - first for squere "4 2" and second squere "3 4". So my question is what does this last comma referrs to ? And obvious - why the other comma isn't in the output ? Thank You. Mike Read correct the task !! There you can see that then last line contains '.' not ',' ! Point ends last line of input. Last line is NOT ONLY POINT! Last line may be the following: RT. POINT using at the last line instead of comma. well i think it must be '.' at last.. because if it can go on .. it will print R L T B .. when print '.' it means at this time it can't go ... Hey everyone, I'm very frustrated. I spent couple hours on this problem and couldn't get it in Java. it's always WA#2. Can anyone give me some test data? I know that input can be any of the two representations, and all test cases given in threads are passed. I have really no clue, what's going on. I also checked for line breaks in input and output files. nothing works Image in first format: 10 1 1 1 2 2 2 2 3 2 4 2 5 3 1 3 2 4 2 4 3 Image in second format: 1 1 T, R, RT, RB, T, T, , T, , . Sorry for late reply! Yes, that's exactly what I get. I don't think that the problem is within algo... I think there is some stupid mistake... something like extra line break or something else... =( The point is to read the statement thoroughly, more precise: Input One representation of the image will be given to your program in the input. Output Your program has to write other representation of the image to the output. I guess you can apply it yourself! I said that: "I know that input can be any of the two representations, and all test cases given in threads are passed." Read carefully before saying something... I'm really agree with you!!!And now I haven't fixed my WA2 yet!!!How can that be!!Could you give me some idea,ile?I have checked my code for a few days... In this task can be specified 2 shows at the input if first string containts 2 Number, input -> 2'st view, else 1'st view. for example: string[] d = Console.ReadLine().Trim().Split(' '); if (d.Length == 1) { Algo 1=>2 } else { Algo 2=>1 } thanks, you are right I had the same problem but found funny bug :) read(...) gets Crash #2 readln(...) gets Accepted |
|