UVa 201 Squares 枚举
来源:互联网 发布:程序员上班3天被劝退 编辑:程序博客网 时间:2024/06/05 17:54
题意:
有n行n列的小黑点,还有m条边连接这些小黑点,统计这些线段连接成几个正方形。
分析:
枚举每个点,看看以这个点为右下角的正方形是否可以,然后枚举边长,控制正方形的大小,判断是否可以构成正方形使用map记录边,然后查询就可以。
#include<iostream>#include<cstdio>#include<map>#include<cstring>using namespace std;typedef pair<int,int>pii;map<pii,int>mp,mpp;int ans[11];int main(){ int n,m,x,y; char op[2]; int cas=0; //freopen("f.txt","r",stdin); //freopen("out.txt","w",stdout); while(~scanf("%d",&n)){ mp.clear();mpp.clear(); memset(ans,0,sizeof(ans)); scanf("%d",&m); while(m--){ scanf("%s%d%d",op,&x,&y); if(op[0]=='H'){ mp[pii(x,y)]=1; } else mpp[pii(x,y)]=1; } // cout<<mp.size()<<' '<<mpp.size()<<endl; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ for(int s=1;s<min(i,j);s++){ if(mp.count(pii(i,j-s))&&mpp.count(pii(j,i-s))){ //cout<<i<<' '<<j<<endl; bool flag=1; for(int x=i-s,y=j-s;x<i&&y<j;x++,y++){ if(mp.count(pii(i-s,y))&&mpp.count(pii(j-s,x)))continue; else{flag=0;break;} } if(flag) ans[s]++; } else break; } } } if(cas){ printf("\n**********************************\n\n"); } printf("Problem #%d\n\n",++cas); bool flag=1; for(int s=1;s<=n;s++){ if(ans[s]){ printf("%d square (s) of size %d\n",ans[s],s); flag=0; } } if(flag)printf("No completed squares can be found.\n"); } return 0;}
0 0
- UVa 201 Squares 枚举
- UVA 201 Squares(枚举)
- Uva 201 Squares (暴力 + 枚举)
- UVA-201Squares
- UVa 201 - Squares
- UVa 201 - Squares
- UVa 201 - Squares
- UVA-201 Squares
- UVA - 201 Squares
- Uva 201 Squares
- UVa-201Squares
- UVa 201 Squares
- UVA - 201 Squares
- UVA 201 Squares
- UVa 201 Squares
- UVA 201 Squares
- UVa 201 Squares
- UVA - 201-Squares
- 稳定的奇偶数字排序
- Chrome浏览器的密码数据
- LeetCode 217 -Contains Duplicate ( JAVA )
- 【剑指 offer】(十三)—— 在 O(1) 时间删除链表结点
- PHP MVC架构
- UVa 201 Squares 枚举
- BUY LOW, BUY LOWER
- C++实现——求三角形的面积(海伦公式)
- leetcode 11. Container With Most Water
- 动画文件的常用格式
- MySQL--基本内容
- android 开启本地相册选择图片并返回显示
- 计算机图形学(一) 视频显示设备_5_平板显示器
- 《算法(第四版)》排序-----堆排序