poj 2653 Pick-up sticks【线段相交】
来源:互联网 发布:淘宝水印美图秀秀教程 编辑:程序博客网 时间:2024/05/16 12:51
点击打开链接
题意:
依次向地上仍n个棍子(按先后顺序),后仍的如果和前面已经扔过的有交点,那么会叠加上去,
题目问最后最上面的木棍有哪些。
题解:
从前向后判断每个木棒上面有没有其他木棒,有的话,直接break。
否则tle。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<map>//#include<pair>#include<cmath>#include<vector>#define x first#define y secondusing namespace std;inline int read(){int x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar())if(c=='-')f=-1;for(;isdigit(c);c=getchar())x=x*10+c-'0';return x*f;}const double eps=1e-8;const double PI=acos(-1.0);const int maxn=1e5+10;int sgn(double x){ if(fabs(x)<eps) return 0; if(x<0) return -1; return 1;}struct Point{ double x,y; Point(){} Point(double _x,double _y){ x=_x;y=_y; } Point operator -(const Point &b)const{ return Point(x-b.x,y-b.y); } double operator ^ (const Point &b)const{ return x*b.y - y*b.x; }};struct Line{ Point s,e; Line(){} Line(Point _s,Point _e){ s=_s;e=_e; }};bool inter(Line l1,Line l2){ return max(l1.s.x,l1.e.x)>=min(l2.s.x,l2.e.x)&& max(l2.s.x,l2.e.x)>=min(l1.s.x,l1.e.x)&& max(l1.s.y,l1.e.y)>=min(l2.s.y,l2.e.y)&& max(l2.s.y,l2.e.y)>=min(l1.s.y,l1.e.y)&& sgn((l2.s-l1.e)^(l1.s-l1.e))*sgn((l2.e-l1.e)^(l1.s-l1.e))<=0&& sgn((l1.s-l2.e)^(l2.s-l2.e))*sgn((l1.e-l2.e)^(l2.s-l2.e))<=0;}Point p1,p2,p3,p4;Line l[maxn],t1;bool v[maxn];vector<int>vec;int main(){ int n,cnt; double x1,x2,y2,y1; while(scanf("%d",&n)&&n){ memset(v,0,sizeof(v)); vec.clear(); for(int i=1;i<=n;++i){ scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2); //x1=read();y1=read();x2=read();y2=read(); p1={x1,y1};p2={x2,y2}; l[i]={p1,p2}; } for(int i=1;i<=n;++i){ for(int j=i+1;j<=n;++j){ if(inter(l[i],l[j])){ v[i]=true; break; } } } printf("Top sticks: "); int f=0; for(int i=1;i<=n;++i) if(!v[i]){ if(!f)printf("%d",i),f=1; else printf(", %d",i); } puts("."); }return 0;}
阅读全文
0 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 Pick-up sticks 线段相交
- poj 2653 Pick-up sticks (线段相交)
- poj 2653 Pick-up sticks【线段相交】
- POJ 2653 线段与线段相交 Pick-up sticks
- POJ 2635 Pick-up sticks (线段相交)
- Poj 2635 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--线段相交--vector
- POJ 2653 Pick-up sticks (判断线段相交)
- Makefile
- Linux系统中软链接和硬链接的区别
- java关于时间处理的函数
- Maximum Product of Three Numbers问题解法
- 泛型的详解
- poj 2653 Pick-up sticks【线段相交】
- Waiting for table metadata lock
- C语言-求两个日期之间的距离
- 关于char *str[]与 char str[]的区别
- Splay树(伸展树)
- mybatis-架构
- 畅通工程
- 第一课、课程简介
- error和exception区别