UVa 270 - Lining Up
来源:互联网 发布:钓鱼岛知乎 编辑:程序博客网 时间:2024/06/04 17:49
题目:给你平面上n个点,求最多有几个点共线。
分析:计算几何。枚举基准点,其他点按基准点极角排序(斜率排序),然后枚举相邻直线判断统计即可。
说明:时间复杂度O(n*n*lg(n))。
#include <algorithm>#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>#include <cmath>using namespace std;typedef struct pnode{double x,y;}point;point P[701];double S[701];int main(){int t;char buf[100];scanf("%d",&t);getchar();gets(buf);while (t --) {int count = 0;while (gets(buf) && buf[0]) {sscanf(buf, "%lf%lf", &P[count].x,&P[count].y);count ++;}int max = 0;for (int i = 0 ; i < count ; ++ i) {int save = 0;for (int j = 0 ; j < count ; ++ j) {if (j == i) continue;if (P[i].x == P[j].x)S[save ++] = 1e1000;elseS[save ++] = (P[j].y-P[i].y)/(P[j].x-P[i].x);}sort(S, S+save);int now = 1;for (int j = 1 ; j < save ; ++ j)if (S[j] == S[j-1])now ++;else {if (max < now) max = now;now = 1;}if (max < now) max = now;}printf("%d\n",max+1);if (t) printf("\n");} return 0;}
0 0
- UVa 270 - Lining Up
- UVa 270 - Lining Up
- uva 270 - Lining Up
- UVa 270 - Lining Up
- UVa 270 - Lining Up
- UVA 270 - Lining Up
- UVA 270 Lining Up
- uva 270 Lining Up
- uva 270 Lining Up
- Lining up(uva 270)
- UVa 270 - Lining Up
- uva 270 - Lining Up
- uva 270 Lining Up
- UVA 270 - Lining Up
- UVA - 270 Lining Up
- Lining Up - UVa 270
- uva 270 Lining Up
- UVA 270 Lining Up
- 《C语言及程序设计》实践参考——血型统计
- prim算法,转过来当模版用
- Maven使用初步
- EEPROM && FLASH
- 易扩展的办公流程化管理核心模型(第2版)
- UVa 270 - Lining Up
- 《c primer plus》编程练习回顾-第五章
- Android自实现activity之间切换,view随手指移动
- windows下实现wamp与tomcat环境整合
- java设计模式之单例模式
- 从0到1
- java.lang.OutOfMemoryError: PermGen space 问题解决办法
- Java8 新方法之 Stream(一)
- Number Sequence