HDU 6055 Regular polygon
来源:互联网 发布:维多利亚2 mac 中文 编辑:程序博客网 时间:2024/05/16 09:23
【题目链接】
http://acm.hdu.edu.cn/showproblem.php?pid=6055
题目意思
给定n个点问你可以形成多少个正多边形。
解题思路
因为给定点为整数,所以只能形成正4边形,因此从上往下,从左往右。任意两个点两两判断剩余其余两点是否在给定点中,最后答案除2,因为ab和ba重复计算
代码部分
#include <bits/stdc++.h>using namespace std;const int maxn=510;struct Node ///存储点{ int x,y; bool operator<(const Node &rhs)const ///排序从上往下从左往右 { if(x == rhs.x) return y < rhs.y; else return x < rhs.x; }} nodes[maxn];int main(){ int n; while(~scanf("%d",&n)) { int ans=0;///正方形个数 for(int i=0; i<n; ++i) scanf("%d%d",&nodes[i].x,&nodes[i].y); sort(nodes,nodes+n); for(int i=0; i<n; ++i) for(int j=i+1; j<n; ++j) { Node tmp; ///tmp作为正方形的第3或4个点 ///特殊方法来判断第三个和第四个点的位置(自己画画图就懂了) tmp.x=nodes[i].x+nodes[i].y-nodes[j].y; tmp.y=nodes[i].y+nodes[j].x-nodes[i].x; if(!binary_search(nodes,nodes+n,tmp)) continue; ///二分查找是否存在这个点 tmp.x=nodes[j].x+nodes[i].y-nodes[j].y; tmp.y=nodes[j].y+nodes[j].x-nodes[i].x; if(!binary_search(nodes,nodes+n,tmp)) continue; ++ans; } ///在两个点为一个边的时候判断了两次,所以结果应该除二 printf("%d\n",ans/2); } return 0;}
阅读全文
0 0
- [HDU]-6055 Regular polygon
- hdu-6055-Regular polygon
- Regular polygon HDU 6055
- hdu--6055--Regular polygon
- HDU 6055 Regular polygon
- hdu 6055 Regular polygon
- hdu 6055 Regular polygon
- HDU 6055 Regular polygon
- hdu 6055 Regular polygon
- hdu 6055 Regular polygon
- HDU 6055 Regular polygon
- HDU 6055 Regular polygon
- HDU 6055 Regular polygon
- HDU-6055 Regular polygon
- HDU-6055-Regular polygon
- 【HDU 6055 Regular polygon】+ map
- Regular polygon(HDU 6055)
- HDU 6055 Regular polygon【几何】
- Java程序员应该知道的10个调试技巧(转载)
- Re0(单调栈)
- 百练4039:IP地址转换题解
- linux定时任务未触发
- Largest Rectangle in a Histogram
- HDU 6055 Regular polygon
- C语言之字符串与指针
- mysql 中 unix_timestamp和from_unixtime 时间戳函数
- 七大查找算法
- Ubuntu下 Nginx 反向代理 Apache、Tomcat
- 贝叶斯推断及其互联网应用(二):过滤垃圾邮件
- AndroidStudio使用Git上传项目至Github
- C语言之结构体与位操作篇
- 冒泡排序 鸡尾酒排序