poj 2653 Pick-up sticks(判断线段是否相交)
来源:互联网 发布:数据库物理模型主键 编辑:程序博客网 时间:2024/04/29 21:47
//以下为原blog搬迁过来的内容
【题目大意】:给出n条木棍,然后依次摆放在桌面上,每次摆放的木棍的起始点和终止点给定,求最上面的木棍的标号
【解题思路】:线段判相交就是了,水题
【代码】:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>#include <cmath>#include <string>#include <cctype>#include <map>#include <iomanip> using namespace std; #define eps 1e-8#define pi acos(-1.0)#define inf 1<<30#define pb push_back#define lc(x) (x << 1)#define rc(x) (x << 1 | 1)#define lowbit(x) (x & (-x))#define ll long longstruct Point{ double x, y; Point() {} Point(double a, double b) { x = a, y = b; }}point[200000];struct Line{ Point a, b; Line() {} Line(Point x, Point y) { a = x, b = y; }}line[150000];int judge[150000],n,m;double p,q;inline int sig(double k){ return k < -eps ? -1 : k > eps;}inline double det(double x1, double y1, double x2, double y2){ return x1 * y2 - x2 * y1;}inline double xmult(Point o, Point a, Point b){ return det(a.x - o.x, a.y - o.y, b.x - o.x, b.y - o.y);}inline double dotdet(double x1, double y1, double x2, double y2){ return x1 * x2 + y1 * y2;}inline double dot(Point o, Point a, Point b){ return dotdet(a.x - o.x, a.y - o.y, b.x - o.x, b.y - o.y);}inline int between(Point o, Point a, Point b){ return sig(dot(o, a, b));}inline int intersect1(Point a, Point b, Point c, Point d){ double s1, s2, s3, s4; int d1 = sig(s1 = xmult(a, b, c)); int d2 = sig(s2 = xmult(a, b, d)); int d3 = sig(s3 = xmult(c, d, a)); int d4 = sig(s4 = xmult(c, d, b)); if ((d1^d2) == -2 && (d3^d4) == -2) { return 1; } if (d1 == 0 && between(c, a, b) <= 0) return 2; if (d2 == 0 && between(d, a, b) <= 0) return 2; if (d3 == 0 && between(a, c, d) <= 0) return 2; if (d4 == 0 && between(b, c, d) <= 0) return 2; return 0;}inline int intersect(Line u, Line v){ return intersect1(u.a, u.b, v.a, v.b);}int main(){ while (~scanf("%d",&n)) { if (n==0) break; for (int i=0; i<n; i++) { scanf("%lf%lf",&p,&q); point[2*i-1]=Point(p,q); scanf("%lf%lf",&p,&q); point[2*i]=Point(p,q); line[i]=Line(point[2*i-1],point[2*i]); } memset(judge,0,sizeof(judge)); for (int i=0; i<n; i++) { for (int j=i+1; j<n; j++) { int k; k=intersect(line[i],line[j]); if (k!=0) {judge[i]=1; break;} } } printf("Top sticks:"); for (int i=0; i<n-1; i++) { if (judge[i]==0) printf(" %d,",i+1); } printf(" %d.\n",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 Pick-up sticks(判断线段相交)
- 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 _判断两线段是否相交
- Pick-up sticks(线段相交判断)
- poj 3304 Segments(利用叉积求是否存在直线与所给线段相交)
- configfs
- poj 1296 Noise Effect(判断线段相交,并求交点)
- 我们要有意识地增加网站中的关键词
- poj 1556 The Doors(最短路+判断线段相交)
- poj 2653 Pick-up sticks(判断线段是否相交)
- c中printf实现atoi实现
- poj 1066 Treasure Hunt(判断线段相交)
- poj 1410 Intersection(判矩形和线段相交。。细节多)
- poj 1696 Space Ant(叉积的性质,做极角排序)
- poj 3347 Kadj Squares(扩大数据运算的典型应用+映射)
- poj 2826 An Easy Problem?!(线段交,细节题)
- poj 1039 Pipe(直线与线段交+枚举直线)
- 我的第一个技术博客