计算几何,判断线段相交

注意题目中的一句话:You may assume that there are no more than 1000 top sticks.

我认为是没有描述清楚的,如果不是每次扔完都保证不超过1000,此题很难做吧。

如果每次扔完保证小于1000根在顶部,那么暴力即可。

开一个vector保存每次扔完在顶部的棒子,下一次扔的时候,只要在删除vector中与扔的相交的棒子,然后再把这个棒子压入进来,最后留下的就是答案

#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<list>
#include<algorithm>
using namespace std; const int maxn=+;
const double eps=1e-;
int totP,totL;
struct point
{
double x;
double y;
} p[*maxn];
struct Line
{
point a;
point b;
int id;
} line[maxn];
vector<Line> v;
vector <Line>::iterator Iter;
vector<int> ans; int flag[maxn]; double xmult(point p1,point p2,point p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
} int opposite_side(point p1,point p2,point l1,point l2)
{
return xmult(l1,p1,l2)*xmult(l1,p2,l2)<-eps;
} int intersect_ex(point u1,point u2,point v1,point v2)
{
return opposite_side(u1,u2,v1,v2)&&opposite_side(v1,v2,u1,u2);
} int main()
{
while(~scanf("%d",&totL))
{
if(!totL) break;
totP=;
for(int i=; i<totL; i++)
{
double a,b,c,d;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
p[totP+].x=a;
p[totP+].y=b;
p[totP+].x=c;
p[totP+].y=d; line[i].a=p[totP+];
line[i].b=p[totP+];
line[i].id=i;
totP=totP+;
}
v.clear();
for(int i=; i<totL; i++)
{
for (Iter=v.begin();Iter!=v.end();)
{
Line now=*Iter;
if(intersect_ex(line[i].a,line[i].b,now.a,now.b))
Iter = v.erase(Iter);
else Iter++;
}
v.push_back(line[i]);
} ans.clear();
for (Iter=v.begin();Iter!=v.end();Iter++ )
{
Line now=*Iter;
ans.push_back(now.id);
}
printf("Top sticks: ");
for(int i=; i<ans.size(); i++)
{
printf("%d",ans[i]+);
if(i<ans.size()-) printf(", ");
else printf(".\n");
}
}
return ;
}

POJ 2653 Pick-up sticks的更多相关文章

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

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

  2. 线段相交 POJ 2653

    // 线段相交 POJ 2653 // 思路:数据比较水,据说n^2也可以过 // 我是每次枚举线段,和最上面的线段比较 // O(n*m) // #include <bits/stdc++.h ...

  3. poj 2653 线段与线段相交

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

  4. The 2015 China Collegiate Programming Contest D.Pick The Sticks hdu 5543

    Pick The Sticks Time Limit: 15000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  5. 2015南阳CCPC D - Pick The Sticks dp

    D - Pick The Sticks Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description The story happened lon ...

  6. CDOJ 1218 Pick The Sticks

    Pick The Sticks Time Limit: 15000/10000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others ...

  7. 2015南阳CCPC D - Pick The Sticks 背包DP.

    D - Pick The Sticks Description The story happened long long ago. One day, Cao Cao made a special or ...

  8. POJ 2653 - Pick-up sticks - [枚举+判断线段相交]

    题目链接:http://poj.org/problem?id=2653 Time Limit: 3000MS Memory Limit: 65536K Description Stan has n s ...

  9. POJ 2653 Pick-up sticks (线段相交)

    题意:给你n条线段依次放到二维平面上,问最后有哪些没与前面的线段相交,即它是顶上的线段 题解:数据弱,正向纯模拟可过 但是有一个陷阱:如果我们从后面向前枚举,找与前面哪些相交,再删除前面那些相交的线段 ...

  10. POJ 2653 Pick-up sticks【线段相交】

    题意:n根木棍随意摆放在一个平面上,问放在最上面的木棍是哪些. 思路:线段相交,因为题目说最多有1000根在最上面.所以从后往前处理,直到木棍没了或者最上面的木棍的总数大于1000. #include ...

随机推荐

  1. namenode ha

    http://blog.csdn.net/totxian/article/details/45248399 http://www.aboutyun.com/thread-13679-1-1.html ...

  2. CSS box-flex属性

    http://www.zhangxinxu.com/wordpress/2010/12/css-box-flex属性,然后弹性盒子模型简介/ http://www.zhangxinxu.com/wor ...

  3. Sublime console installation instructions install Package Control

    instructions: import urllib2,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1 ...

  4. 关于Winform中的用户代理

    问题描述: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 解释: 1. 应用程序版本“Mozilla ...

  5. struts2修改文件上传的大小

    那天写了一个web上传图片的程序,明明修改了上传文件的默认值(2M),可就是一直没有起作用 <action name="fileupload" class="upl ...

  6. java 反射的实例

    JAVA反射机制是在运行状态中,对于任意一个类,都能够得到这个类的所有属性和方法;对于任意一个对象,都能够调用它的任意一个方法;这种动态获取的信息以及动态调用对象的方法的功能称为java语言的反射机制 ...

  7. java 协调同步的线程

    Example12_8.java public class Example12_8 { public static void main(String args[ ]) { TicketHouse of ...

  8. Linux学习 -- Shell基础 -- Bash基本功能

    历史命令 history -c   clear -w   写入 ~/.bash_history 默认保存1000条, 可在/etc/profile中修改 调用 Tab补全 命令.目录.文件 命令别名 ...

  9. python插入mysql新值

    #Server Connection to MySQL: import MySQLdb conn = MySQLdb.connect(host= "localhost", user ...

  10. 移动端touch点穿(穿透)解决办法

    回答一 穿透(点穿)是在mobile各种浏览器上发生的常见的bug.可能是由click事件的延迟或者事件冒泡导致. 移动web开发常用的Zepto库中的touch和tap事件就会有点穿的bug(Zep ...