POJ 2653 Pick-up sticks(计算几何 求交点)
来源:互联网 发布:美少女万华镜 for mac 编辑:程序博客网 时间:2024/05/17 21:53
题意:依次给你n根棍子,问最上面的棍子是哪几根。
直接暴力,TLE,,用一个双向链表优化 500ms
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <queue>using namespace std;const double EPS = 1e-6;const double INF = 1e20;struct cvector{ double x,y; cvector(double a,double b){x=a,y=b;} cvector(){}};cvector operator+(cvector a,cvector b){ return cvector(a.x+b.x,a.y+b.y);}cvector operator-(cvector a,cvector b){ return cvector(a.x-b.x,a.y-b.y);}cvector operator*(double a,cvector b){ return cvector(a*b.x,a*b.y);}double operator*(cvector a,cvector b){ return a.x*b.x+a.y*b.y;}double operator^(cvector a,cvector b){ return a.x*b.y-b.x*a.y;}double length(double t){return t>0?t:-t;}double length(cvector t){return sqrt(t*t);}struct cpoint{ double x,y; cpoint(double a,double b){x=a,y=b;} cpoint(){}};cvector operator-(cpoint a,cpoint b){ return cvector(b.x-a.x,b.y-a.y);}double dist(cpoint a,cpoint b){ return length(b-a);}struct cline{ cpoint a,b;};bool intersect(cline a,cline b){ return ((a.a-b.a)^(b.b-b.a))*((a.b-b.a)^(b.b-b.a))<EPS&&((b.a-a.a)^(a.b-a.a))*((b.b-a.a)^(a.b-a.a))<EPS;}const int N = 100009;int ans[N];cline line[N];int fron[N],nex[N];int main(){ freopen("in.txt","r",stdin); int n; while(~scanf("%d",&n)&&n) { for(int i=1;i<=n;i++) { ans[i] = 1;nex[i] = i-1;fron[i-1] = i; scanf("%lf%lf%lf%lf",&line[i].a.x,&line[i].a.y,&line[i].b.x,&line[i].b.y); for(int j=i-1;j>0;) { if(ans[j]&&intersect(line[j],line[i])) { nex[fron[j]] = nex[j]; fron[nex[j]] = fron[j]; ans[j] = 0; } j = nex[j]; } } fron[n] = n+1; printf("Top sticks: "); bool ou = false; for(int i=fron[0];i<=n;) { if(ou) printf(", ");ou = true; printf("%d",i); i=fron[i]; } printf(".\n"); } return 0;}
- POJ 2653 Pick-up sticks(计算几何 求交点)
- POJ 2653 Pick-up sticks(计算几何 求线段交点)
- poj 2653 Pick-up sticks 计算几何
- poj 2653 Pick-up sticks 计算几何
- POJ 2653 Pick-up sticks <计算几何>
- POJ 2653 Pick-up sticks 计算几何 线段相交
- POJ 2653 && HDU 1147 Pick-up sticks(计算几何)
- POJ 2653 Pick-up sticks【计算几何入门】
- poj 2653 Pick-up sticks(计算几何)
- POJ 2653 Pick-up sticks [线段相交]【计算几何】
- POJ 2653 Pick-up sticks --队列,几何
- POJ 2653 - Pick-up sticks 重拾计算几何..暴力得不忍直视...
- POJ 2653 Pick-up sticks(计算几何,判断线段相交)
- poj Pick-up sticks 2653 (计算几何 直线相交的判断)
- hdoj 1147 Pick-up sticks 计算几何
- 计算几何-hdoj-1147-Pick-up sticks
- [POJ2653]Pick-up sticks(计算几何)
- POJ2653 Pick-up sticks(计算几何)
- 精通Javascript之引用
- visualstudio 快速搜索功能及相同变量引用之间的跳转
- 一个scrapy抓取网站独立脚本
- 如何发布打包并发布自己的Android应用
- oracle数据库分区
- POJ 2653 Pick-up sticks(计算几何 求交点)
- UIView学习笔记
- Collections.reverseOrder
- sizeof用法注意
- C编写以二进制读取文件(任意格式eg :图片),保存到C语言数据格式的TXT文档
- Gevent使用多进程例子
- 查询数据库系统参数
- 如何将远程SQL Server数据库备份到本地数据库
- 关于字符指针和字符数组的一些错误