捕捉到一只神奇的bug

UVA297 Quadtrees

希望更丰富的展现?使用Markdown
by lihanyang @ 2018-12-29 16:22:31


可能是有数组越界 数组顺序不同越界到的位置不同 就有了AC和挂
by a2956331800 @ 2018-12-29 16:24:32


不会,第一次发帖。。。所以,发成了这个样子
by Vict @ 2018-12-29 16:24:38


@[Vict](/space/show?uid=162440) 在代码的头和尾换行各加一个``` 就是1左边那个键 ``` # include <bits/stdc++.h> ```
by Meatherm_test @ 2018-12-29 16:28:01


@[a2956331800](/space/show?uid=9517) o(╥﹏╥)o不懂,全局变量的声明顺序会有影响?就是这两行的顺序。 char s[maxn]; int buf[len][len],cnt;
by Vict @ 2018-12-29 16:29:14


@[Vict](/space/show?uid=162440) 顺序没影响 你开大点就行了嘛
by XMK_萌新 @ 2018-12-29 16:39:15


@[Vict](/space/show?uid=162440) 能把完整的代码发上来么?使用插入代码功能(就是发帖区工具栏上形如 `</>` 的那个按钮,**或者**在你的代码前后加三个 \` 字符,就像这样 ``` #include <cstdio> ``` 实际效果 ```cpp #include <cstdio> ```
by Prurite @ 2018-12-29 16:56:57


``` #include<cstdio> #include<cstring> const int len=32; const int maxn=1024+10; char s[maxn];//这两行有毒,如果调换了这两行的顺序,就过不了oj int buf[len][len],cnt;//还不清楚原因,不过貌似和初始化的顺序有关,以后先用到的全局变量放在后面; void draw(const char* s,int& p,int r,int c,int w) { char ch=s[p++]; if(ch=='p') { draw(s,p,r ,c+w/2,w/2); draw(s,p,r ,c ,w/2); draw(s,p,r+w/2,c ,w/2); draw(s,p,r+w/2,c+w/2,w/2); } else if(ch=='f') { for(int i=r; i<r+w; i++) for(int j=c; j<c+w; j++) if(buf[i][j]==0) { buf[i][j]=1; cnt++; } } } int main() { int T; scanf("%d",&T); while(T--) { cnt=0; memset(buf,0,sizeof(buf));//buf和cnt的刷新在循环里; for(int i=0; i<2; i++) { scanf("%s",s); int p=0;//p的刷新在每一次输入s里; draw(s,p,0,0,len); } printf("There are %d black pixels.\n", cnt); } return 0; } ``` 完整的代码(其实就是汝佳的算法;在学紫书,(`・ω・´),每次学完自己打总会出些奇奇怪怪的问题;
by Vict @ 2018-12-29 18:01:59


@[星烁晶熠辉](/space/show?uid=54160) Thanks♪(・ω・)ノ
by Vict @ 2018-12-29 18:02:39


|