UVA 201 Squares——思路题

网友投稿 535 2022-11-29

UVA 201 Squares——思路题

UVA 201 Squares——思路题

按照边长从小到大输出,不是个数,因为这个错了一遍。。。

#include #include #include int main(){ int squar[20][20]; int n, m, flag = 0; while( scanf("%d %d",&n, &m) == 2 ){getchar(); memset(squar,0,sizeof(squar)); while(m--){ char c; int x, y; scanf("%c%d%d",&c, &x, &y);getchar(); if(c == 'H' && squar[x][y] == 0) squar[x][y] = 1; else if(c == 'V' && squar[y][x] == 0) squar[y][x] = 2; else if(c == 'H' && squar[x][y] == 2) squar[x][y] = 3; else if(c == 'V' && squar[y][x] == 1) squar[y][x] = 3; }// for(i = 1; i <= n; i++){ for(j = 1; j <=n; j++) printf("%-3d",squar[i][j]);printf("\n");} int num[15] = {0}; int i, j, k; for(k = 1; k <= n-1; k++) for(i = 1; i <= n-k; i++) for(j = 1; j <= n-k; j++){ int x, y, on_off = 0; for(x = i; x < i+k; x++){ if((squar[x][j] == 2 || squar[x][j] == 3) && (squar[x][j+k] == 2 || squar[x][j+k] == 3)); else break; } if(x >= i+k) on_off++; for(y = j; y < j+k; y++){ if((squar[i][y] == 1 || squar[i][y] == 3) && (squar[i+k][y] == 1 || squar[i+k][y] == 3)); else break; } if(y >= j+k) on_off++; if(on_off == 2) num[k]++; } if(flag!=0) printf("\n**********************************\n\n"); printf("Problem #%d\n\n",++flag); int count = 0; for(i = 1; i <= 10; i++) if(num[i] != 0){ printf("%d square (s) of size %d\n", num[i], i); count++; } if(count == 0) printf("No completed squares can be found.\n"); } return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:UVA 1589 Xiangqi——模拟
下一篇:UVA 1374 Power Calculus——暴力打表
相关文章

 发表评论

暂时没有评论,来抢沙发吧~