uva 201 数正方形数
来源:互联网 发布:linux查看进程占用内存 编辑:程序博客网 时间:2024/04/27 14:28
http://acm.bnu.edu.cn/v3/contest_show.php?cid=5772#problem/B
给你一个由点组成的网格,再给一些连结相邻点的操作(横向、纵向),统计里面的正方形,从小到大输出其数量。
水题,依次枚举边长,判断每个点为左上角时能否构成正方形..
#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <queue>#include <map>#include <iostream>#include <sstream>#include <algorithm>using namespace std;#define RD(x) scanf("%d",&x)#define RD2(x,y) scanf("%d%d",&x,&y)#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)#define clr0(x) memset(x,0,sizeof(x))#define clr1(x) memset(x,-1,sizeof(x))#define eps 1e-9const double pi = acos(-1.0);typedef long long LL;const int inf = 1000000000;const int maxn = 15;int h[maxn][maxn],v[maxn][maxn],n,m;int main(){ int _ = 0; while(~RD2(n,m)){ int x,y; char typ[2]; clr0(h),clr0(v); while(m--){ scanf("%s",typ); RD2(x,y); if(typ[0] == 'H') h[x][y] = 1; else v[y][x] = 1; } if(_++) puts("\n**********************************\n"); printf("Problem #%d\n\n",_); int sum = 0; for(int l = 1;l <= n;++l){ int cnt = 0; for(int i = 1;i + l <= n;++i) for(int j = 1;j + l <= n;++j){ int flag = 1; for(int hh = j;hh < j + l;++hh) if(!h[i][hh] || !h[i+l][hh]) flag = 0; for(int vv = i;vv < i + l;++vv) if(!v[vv][j] || !v[vv][j+l]) flag = 0; cnt += flag; } sum += cnt; if(cnt) printf("%d square (s) of size %d\n",cnt,l); } if(!sum) puts("No completed squares can be found."); } return 0;}
0 0
- uva 201 数正方形数
- 完全数(亏数、盈数)、三角形数、棱锥体数、正方形数
- 正方形包含最多正方形数
- 正方形等分计数总正方形数
- UVA10177数出二维三维四维中的正方和矩方数
- 【HDU3629】n个点组成的凸四边形数 极角atan2+组合数
- 三角形数
- 守形数
- 三角形数
- 三角形数
- 平行四边形数
- 平行四边形数
- 平行四边形数
- 守形数
- 守形数
- 平行四边形数
- 平行四边形数
- 平行四边形数
- JAVA的四种引用
- 最大连续子序列
- 关于Python中的for循环控制语句
- 编译小米2s CyanogenMod 版本遇到的几个问题 (02.26更新)
- Python学习笔记一:数据类型转换
- uva 201 数正方形数
- java类的装载(Loading)、链接(Linking)和初始化(Initialization)
- K-Means聚类算法
- Python学习笔记二:布尔表达式
- Python学习笔记三:逻辑操作符
- UML类图实例
- 12.7 给计算增加日志记录
- 【转载】.bash_profile和.bashrc的区别(如何设置生效)
- Python学习笔记四:if语句