http://poj.org/problem?id=2653

题目大意:有n根各种长度的棍   一同洒在地上 求在最上面的棍子有那几个

分析:  我刚开始想倒着遍历  因为n是100000   想着会超时吧  后来一看说  在上面的不会超过1000个 这就放心了 简单优化一下就过了

最后一个肯定是在最上面的 让后从他的下一个开始  每一个跟他相交的都是在他下面的  下一次就直接不循环他了

但是一直wa   彻底懵逼了

后来看了学长博客  他是正这循环  只要有跟他相交的就跳出  然后我就正这便利了一下  竟然过了  神奇ing   !!!

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
#include<algorithm>
#include<iostream> using namespace std;
#define N 100050
const double ESP = 1e-;
#define INF 0xffffffff
int vis[N];
struct Point
{
double x,y;
Point (double x=,double y=):x(x),y(y) {}
Point operator - (const Point &temp)const
{
return Point(x-temp.x,y-temp.y);
}
bool operator == (const Point &temp)const
{
return (fabs(temp.x-x)<ESP && fabs(temp.y-y)<ESP);
} int operator * (const Point &temp)const
{
double t=(x*temp.y)-(y*temp.x);
if(t>ESP)
return ;
if(fabs(t)<ESP)
return ;
return -;
}
}; struct node
{
Point A,B;
node(Point A=,Point B=):A(A),B(B) {}
}; node a[N];
Point p[N];
int s[N];
int main()
{
int n;
while(scanf("%d",&n),n)
{
int b=;
double x1,x2,y1,y2;
for(int i=; i<=n; i++)
{
scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
p[b++]=Point(x1,y1);
p[b++]=Point(x2,y2);
a[i]=node(p[b-],p[b-]);
}
memset(vis,,sizeof(vis));
memset(s,,sizeof(s));
b=;
for(int i=;i<=n;i++)
{
int flag=;
for(int j=i+;j<=n;j++)
{
int k=abs((a[i].A-a[j].A)*(a[j].B-a[j].A)+(a[i].B-a[j].A)*(a[j].B-a[j].A));
int kk=abs((a[j].A-a[i].A)*(a[i].B-a[i].A)+(a[j].B-a[i].A)*(a[i].B-a[i].A));
if(kk== && k==)
{
flag=;
break;
}
}
if(flag==)
s[b++]=i;
}
printf("Top sticks: ");
if(b==)
{
printf("%d.\n",s[]);
continue;
}
for(int i=; i<b-; i++)
{
printf("%d, ",s[i]);
}
printf("%d.\n",s[b-]);
}
return ;
}

Pick-up sticks--poj2653(判断两线段是否相交)的更多相关文章

  1. You can Solve a Geometry Problem too(判断两线段是否相交)

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  2. NYOJ 1016 判断两线段是否相交

    #include<cstdio> #include<cmath> #include<iostream> #include<algorithm> #inc ...

  3. You can Solve a Geometry Problem too (hdu1086)几何,判断两线段相交

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/3276 ...

  4. hdu 1086:You can Solve a Geometry Problem too(计算几何,判断两线段相交,水题)

    You can Solve a Geometry Problem too Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/3 ...

  5. hdu 1147:Pick-up sticks(基本题,判断两线段相交)

    Pick-up sticks Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  6. poj 1127:Jack Straws(判断两线段相交 + 并查集)

    Jack Straws Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2911   Accepted: 1322 Descr ...

  7. UVALive7461 - Separating Pebbles 判断两个凸包相交

    //UVALive7461 - Separating Pebbles 判断两个凸包相交 #include <bits/stdc++.h> using namespace std; #def ...

  8. 如何判断单链表是否存在环 & 判断两链表是否相交

    给定一个单链表,只给出头指针h: 1.如何判断是否存在环? 2.如何知道环的长度? 3.如何找出环的连接点在哪里? 4.带环链表的长度是多少? 解法: 1.对于问题1,使用追赶的方法,设定两个指针sl ...

  9. poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)

    Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...

随机推荐

  1. [实用技巧] Mac下面如何通过终端快速打开当前文件夹

    Mac mac里面其实很简单,直接输入 open .,注意是open + 英文句点. Windows windows里面是start .,注意是start  + 英文句点.

  2. How `delete’ works ?

    这是2013年写的一篇旧文,放在gegahost.net上面 http://raison.gegahost.net/?p=21 February 16, 2013 How `delete’ works ...

  3. gulp自动化构建工具使用

    gulpfile.js: var gulp = require("gulp"); var imagemin = require("gulp-imagemin") ...

  4. Oracle错误 1053: 该服务没有响应启动或控制请求

    在服务中,启动oracleDBConsolenewdb服务时,出现了 错误 1053: 该服务没有响应启动或控制请求 在网上查了以后你会发现这是一个非常宽泛的错误,然而我们的建议是去看传说中的orac ...

  5. EOS Dawn 3.0 智能合约 -- 新格式

    1.简介 随着EOS Dawn 3.0发布,智能合约的坑又要重新踩了o(╥﹏╥)o:3.0不仅将原来本身就在链里的基础合约独立出来,简单的介绍见3.0合约改变,合约的书写方式也有巨大变化,相比之前更加 ...

  6. Python3简明教程(十四)—— Collections模块

    collections 是 Python 内建的一个集合模块,提供了许多有用的集合类. 在这个实验我们会学习 Collections 模块.这个模块实现了一些很好的数据结构,它们能帮助你解决各种实际问 ...

  7. Linux 常用命令:解压缩

    目录 Linux 常用命令:解压缩 说明 tar 涉及参数说明: 压缩 解压 zip压缩 涉及参数说明: uzip解压 涉及参数说明: gzip 涉及参数说明: 压缩率比较 Linux 常用命令:解压 ...

  8. 通俗理解 模糊自适应PID

    模糊自适应PID算法就是在经典的PID的基础上添加模糊控制规则库,建立这个库的目的就是算法能够自己来进行改变P.I.D的值. 就拿温度的上升过程控制来说,刚开始的时候,希望温度能够快速的升到终点温度, ...

  9. STL || HDU 1894 String Compare

    如果一个词包含再另一个词的前面(前缀),是一对前缀,求一共有多少对 *解法:STL万岁 #include<string>:https://www.cnblogs.com/SZxiaochu ...

  10. ProxyFactory

    Spring定义了org.springframework.aop.framework.AopProxy接口,并提供了两个final类型的实现类. AopProxy类结构: