poj2187 凸包直径模板
来源:互联网 发布:广联达软件官方下载 编辑:程序博客网 时间:2024/06/02 20:09
#include <iostream>#include <cmath>#include <algorithm>#include <cstdio>using namespace std;#define INF 50005struct Node{ double x, y;};Node point[INF];int n, s[INF], top;double cross(Node a, Node b, Node c){ double x1 = a.x - c.x; double y1 = a.y - c.y; double x2 = b.x - c.x; double y2 = b.y - c.y; return x1 * y2 >= x2 * y1;}double dis(Node a, Node b){ return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}int cmp(Node a, Node b){ if(a.y==b.y) return a.x<b.x; return a.y<b.y;}void graham(){ int i; sort(point, point+n, cmp); top = 1; s[0] = 0; s[1] = 1; s[2] = 2; for (i=2; i<n; i++) { while (top && cross(point[i], point[s[top]], point[s[top-1]])) top--; s[++top] = i; } int len = top; s[++top] = n - 2; for (i=n-3; i>=0; i--) { while (len!=top && cross(point[i], point[s[top]], point[s[top-1]])) top--; s[++top] = i; }}int main(){ int i, j; while (scanf("%d", &n)!=EOF) { for (i=0; i<n; i++) scanf("%lf%lf", &point[i].x, &point[i].y); if (n<3) printf("%.lf\n", dis(point[0], point[1])); else { graham(); double ans = 0; for(i = 0; i < top-1; i ++) for(j = i+1; j < top; j ++) ans = max(ans, dis(point[s[i]], point[s[j]]));//G++用%f printf("%.lf\n", ans); } } return 0;}
再一次遇到这一题时,相同的代码wrong到死
在老师的帮助下找到原因
如果输出的是小数,在G++用"%f"输出就能AC,而用"%lf"输出就会WA,而C++就没这个问题。
ISO C只允许用%f输出小数,%lf属于非标准用法。(http://poj.org/page?id=1000 Other questions一节)
ISO C只允许用%f输出小数,%lf属于非标准用法。(http://poj.org/page?id=1000 Other questions一节)
0 0
- poj2187 凸包直径模板
- poj2187 凸包问题
- poj2187 凸包
- poj2187凸包
- POJ2187凸包
- POJ2187->凸包
- poj2187(凸包)
- poj2187(凸包)
- poj2187(凸包)
- 求凸包直径 poj2187
- POJ2187--凸包--Beauty Contest
- poj2187 Beauty Contest 凸包
- POJ2187 Beauty Contest 凸包+旋转卡壳
- poj2187 Beauty Contest 凸包+旋转卡壳
- POJ2187 Andrew凸包+旋转卡壳
- poj2187 Beauty Contest 凸包 Graham扫描
- 【POJ2187】Beauty Contest-凸包+旋转卡壳
- 二维凸包模板(凸包重心,周长,面积,直径,最大三角形,最小环绕矩形)
- C语言中volatile关键字的作用
- POJ 1265 Area
- ARM7裸机开发学习日志01
- 简单图形界面程序
- poj 1149 PIGS 最大网络流
- poj2187 凸包直径模板
- poj 1265 Area(pick 定理)
- 绝不在构造和析构过程中调用virtual函数 UC2014年实习生笔试题
- protel component not found
- 一张浏览器加载时序图。以后有时间再分析
- java for循环注意事项
- 关闭VirtualBox虚拟机的时钟同步
- hdu1874
- hdu1518