题意:给定n个木棍依次放下,要求最终判断没被覆盖的木棍是哪些。

思路:快速排斥以及跨立实验可以判断线段相交。

 #include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
const double eps=1e-;
struct Point{
double x,y;
Point(){}
Point(double x0,double y0):x(x0),y(y0){}
}s[],e[];
int ans[],st[],n;
double operator *(Point p1,Point p2){
return p1.x*p2.y-p1.y*p2.x;
}
Point operator -(Point p1,Point p2){
return Point(p1.x-p2.x,p1.y-p2.y);
}
bool judge(Point p1,Point p2,Point p3,Point p4){
if (std::min(p1.x,p2.x)>std::max(p3.x,p4.x)||
std::min(p1.y,p2.y)>std::max(p3.y,p4.y)||
std::min(p3.x,p4.x)>std::max(p1.x,p2.x)||
std::min(p3.y,p4.y)>std::max(p1.y,p2.y))
return ;//快速排斥实验
double a,b,c,d;
a=(p2-p1)*(p3-p1);
b=(p2-p1)*(p4-p1);
c=(p4-p3)*(p1-p3);
d=(p4-p3)*(p2-p3);
return (a*b<=eps)&&(c*d<=eps);//跨立实验
}
int main(){
while (scanf("%d",&n)!=EOF&&n){
for (int i=;i<=n;i++) ans[i]=;
for (int i=;i<=n;i++){
scanf("%lf%lf%lf%lf",&s[i].x,&s[i].y,&e[i].x,&e[i].y);
}
for (int i=;i<=n;i++)
for (int j=i+;j<=n;j++)
if (judge(s[i],e[i],s[j],e[j]))
{ ans[i]=;
break;
}
int top=;
for (int i=;i<=n;i++)
if (!ans[i])
st[++top]=i;
printf("Top sticks:");
for (int i=;i<top;i++)
printf(" %d,",st[i]);
printf(" %d.\n",st[top]);
}
}

POJ 2653 Pick-up sticks(线段相交)的更多相关文章

  1. 【POJ 2653】Pick-up sticks 判断线段相交

    一定要注意位运算的优先级!!!我被这个卡了好久 判断线段相交模板题. 叉积,点积,规范相交,非规范相交的简单模板 用了“链表”优化之后还是$O(n^2)$的暴力,可是为什么能过$10^5$的数据? # ...

  2. POJ 2653 Pick-up sticks [线段相交 迷之暴力]

    Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12861   Accepted: 4847 D ...

  3. POJ 1066 Treasure Hunt (线段相交)

    题意:给你一个100*100的正方形,再给你n条线(墙),保证线段一定在正方形内且端点在正方形边界(外墙),最后给你一个正方形内的点(保证不再墙上) 告诉你墙之间(包括外墙)围成了一些小房间,在小房间 ...

  4. POJ 1410 Intersection --几何,线段相交

    题意: 给一条线段,和一个矩形,问线段是否与矩形相交或在矩形内. 解法: 判断是否在矩形内,如果不在,判断与四条边是否相交即可.这题让我发现自己的线段相交函数有错误的地方,原来我写的线段相交函数就是单 ...

  5. POJ 1269 Intersecting Lines(线段相交,水题)

    id=1269" rel="nofollow">Intersecting Lines 大意:给你两条直线的坐标,推断两条直线是否共线.平行.相交.若相交.求出交点. ...

  6. POJ 1066 Treasure Hunt【线段相交】

    思路:枚举四边墙的门的中点,与终点连成一条线段,判断与其相交的线段的个数.最小的加一即为答案. 我是傻逼,一个数组越界调了两个小时. #include<stdio.h> #include& ...

  7. poj 1556 (Dijkstra + Geometry 线段相交)

    链接:http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  8. POJ 3304 Segments[直线与线段相交]

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13514   Accepted: 4331 Descrip ...

  9. POJ 1408 Fishnet【枚举+线段相交+叉积求面积】

    题目: http://poj.org/problem?id=1408 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

随机推荐

  1. MYSQL错误解决:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' ( ...

  2. 【转】Android中引入第三方Jar包的方法(java.lang.NoClassDefFoundError解决办法)

    原文网址:http://www.blogjava.net/anchor110/articles/355699.html 1.在工程下新建lib文件夹,将需要的第三方包拷贝进来.2.将引用的第三方包,添 ...

  3. 黑马程序员_Java基本数据类型对象包装类

    基本数据类型对象包装类 byte Byte short Short int Integer long Long boolean Boolean float Float double Double ch ...

  4. bzoj1619[Usaco2008 Nov]Guarding the Farm 保卫牧场

    Description The farm has many hills upon which Farmer John would like to place guards to ensure the ...

  5. poj1011 Sticks(dfs+剪枝)

    Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 110416   Accepted: 25331 Descrip ...

  6. c语言结构体4之结构体引用

    struct mystruct{ char str[23];}; 1结构体变量不能整体引用 struct data m: printf("%s",m);//m是结构体变量 2 st ...

  7. Fiddler 抓取eclipse中的请求

    Fiddler 抓取eclipse中的请求 代码中添加 System.setProperty("http.proxySet", "true"); System. ...

  8. 解决IE6下DIV无法实现1px高度问题

    2.多加一个line-height:1px的属性,不过得在DIV里多加一个 ,也就是空格,以下为引用的内容: <styletypestyletype="text/css"&g ...

  9. python 标准库基础学习之开发工具部分1学习

    #2个标准库模块放一起学习,这样减少占用地方和空间#标准库之compileall字节编译源文件import compileall,re,sys#作用是查找到python文件,并把它们编译成字节码表示, ...

  10. (转)A drop-in universal solution for moving text fields out of the way of the keyboard

    There are a hundred and one proposed solutions out there for how to move UITextField andUITextView o ...