17暑假多校联赛2.11 HDU 6055 Regular polygon
来源:互联网 发布:系统垃圾清理软件 编辑:程序博客网 时间:2024/06/06 01:14
Regular polygon
Time Limit: 3000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description
On a two-dimensional plane, give you n integer points. Your task is to figure out how many different regular polygon these points can make.
Input
The input file consists of several test cases. Each case the first line is a numbers N (N <= 500). The next N lines ,each line contain two number Xi and Yi(-100 <= xi,yi <= 100), means the points’ position.(the data assures no two points share the same position.)
Output
For each case, output a number means how many different regular polygon these points can make.
Sample Input
40 00 11 01 160 00 11 01 12 02 1
Sample Output
12
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6055
分析
题意:给出n个点,判断这些点能够构成多少个正多边形
形成正多边形需要每条边都相等,因为没点坐标都为整数,所以能构成的正多边形只有正方形,可以先将各个点排序可以按照先横坐标再纵坐标,也可以按照先纵坐标再横坐标,然后先选中两个点再往这两个点的上方或者右上方确定能组成正方形的点的坐标,然后判断这两个坐标是否在已给的坐标中
代码
#include <iostream>#include <stdio.h>#include <math.h>#include <string.h>#include <algorithm>#define pf(a) a*ausing namespace std;int N;struct point{ int x,y;} p[510];///存放给的点的坐标bool cmp(struct point a,struct point b){ if(a.y==b.y)///按照在坐标系中的位置先下再左的顺序排序 { return a.x<b.x; } else return a.y<b.y;}bool findp(int x,int y)///查找点(x,y)是否在给定的点中{ for(int i=0; i<N; i++) { if(y==p[i].y&&x==p[i].x) { return true; } } return false;}int main(){ while(~scanf("%d",&N)) { int sum=0; for(int i=0; i<N; i++) { scanf("%d %d",&p[i].x,&p[i].y); } sort(p,p+N,cmp);///将给的点排序 for(int i=0; i<N-1; i++) { for(int j=i+1; j<N; j++)///让所有点都相互连接来作为正方形的一条边 { if(p[i].y==p[j].y||(p[j].y>p[i].y&&p[j].x<p[i].x))///排序之后点p[j]的y值总是大于等于p[i]的y,因为要避免重复查点,所以只查询上方和右上方的可以构成正方形的点,所以p[j]的y大于p[i]的y时,它的x要小于p[i]的x,然后查找满足构成正方形的点 { if(p[i].y==p[j].y) { if((findp(p[i].x,(p[i].y+abs(p[i].x-p[j].x))))&&findp(p[j].x,(p[j].y+abs(p[i].x-p[j].x)))) sum++; } else { if((findp((p[i].x+abs(p[i].y-p[j].y)),(p[i].y+abs(p[i].x-p[j].x))))&&(findp((p[j].x+abs(p[i].y-p[j].y)),(p[j].y+abs(p[i].x-p[j].x))))) sum++; } } } } printf("%d\n",sum); }}
- 17暑假多校联赛2.11 HDU 6055 Regular polygon
- hdu 多校联赛 Regular polygon
- HDU 2017多校联赛-Regular polygon
- HDU 2017 多校联赛2 1011 Regular polygon
- HDU 6053 TrickGCD+6055 Regular polygon【2017多校联赛2】
- HDU6055 Regular polygon(计算几何,2017 HDU多校联赛 第2场)
- HDU6055 Regular polygon +多校联赛第二场
- Regular polygon(2017多校联赛2。 计算几何)
- [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
- 从MVC到前后端分离(REST-个人也认为是目前比较流行和比较好的方式)
- CSS常用样式总结
- 通过Dialer拨号盘输暗码启动某个apk
- Java:按值传递与按引用传递
- Apache引入mod_evasive模块防止ddos攻击
- 17暑假多校联赛2.11 HDU 6055 Regular polygon
- iOS开发中数据库常用的语句
- 最大流-SAP算法
- easyUI下datagrid嵌套显示
- android使用UncaughtExceptionHandler捕获全局异常(闪退)
- sdut 1265 马拦过河卒
- interface与指针类型小测试
- 笨方法学Python 习题 17: 更多文件操作
- Android 合适的地方高效实用SparseArray,SparseBooleanArray,SparseBooleanArray代替Java中map