poj 3304
来源:互联网 发布:车载导航一机多图软件 编辑:程序博客网 时间:2024/05/29 15:07
浮点数真的是日了狗了,我操,
题意:给出n个线段,求是否有一条直线,使得这n个线段在这条直线上的投影 有一个公共点。其实就是问有没有一条直线可以穿过所有的线段,该直线的垂线就是 n个线段的投影线。 TMD沙比的不行啊,浮点数判0 ,要用fabs < eps; `
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>using namespace std;int n;struct point{ double x,y;};struct line{ double a,b,c;};struct seg { point a; point b;};seg data[200]={}; point ans[300]={};void Coeffcient(line &L,point a,point b) { L.a = (a.y-b.y); L.b = (b.x-a.x); L.c = -L.a*a.x-L.b*a.y;}bool jiao(line L,point a,point b) { // 线段ab 在直线L的两侧; double A = a.x*L.a+a.y*L.b+L.c; double B = b.x*L.a+b.y*L.b+L.c; ***if(A*B <= 0 || (fabs(A) < 0.00000001 || fabs(B) < 0.00000001)) return 1;*** return 0;}bool solve() { int len = n*2; for(int i = 0; i < len; i++) { for(int j = i + 1; j < len; j++) { line L; Coeffcient(L,ans[i],ans[j]); bool flag = 1; if(fabs(ans[i].x-ans[j].x) < 0.00000001 && fabs(ans[i].y-ans[j].y) < 0.00000001) continue; for(int k = 0; k < n; k++) { if(jiao(L,data[k].a,data[k].b)) continue; else { flag = 0; break; } } if(flag) return 1; } } return 0;}int main() { int t;scanf("%d",&t); while(t--) { scanf("%d",&n); int co = 0; for(int i = 0; i < n; i++) { scanf("%lf %lf %lf %lf",&data[i].a.x,&data[i].a.y,&data[i].b.x,&data[i].b.y); ans[co++] = data[i].a;ans[co++] = data[i].b; } if(solve()) printf("Yes!\n"); else printf("No!\n"); } return 0;}
0 0
- POJ 3304
- poj 3304
- poj 3304
- poj 3304
- poj 3304
- POJ-3304
- poj 3304
- poj 3304
- poj 3304
- POJ 3304
- poj 3304
- POJ 3304 Segments
- POJ 3304 计算几何
- poj 3304 Segments
- poj 3304 Segments
- poj 3304 Segments
- POJ 3304 Segments
- poj 3304解题报告
- [LeetCode][Java] Text Justification
- 也谈jconsole tomcat内存监控设置
- Spark入门-WordCount
- 安装gcc-4.8.2时遇到的问题及解决方案
- Android 使用ptrace查看其它进程的内存数据
- poj 3304
- Source Insight 使用方法入门
- UVA11988 Broken Keyboard (a.k.a. Beiju Text)
- hdu 1565 网络流(EK算法)
- HDU 1715 大菲波数(高精度——加法)
- JavaScript 变量 作用域 内存
- Java中主函数的含义
- 【cocos2d-x】CCDirector
- Codeforces Round #276 (Div. 2) C. Bits 二进制