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. VBA Promming入门教程——变量的使用

    数据类型 VBA中的数据类型可分为两种 示例 String Sub Main Dim s as string s = "Hello" msgbox(s) End Sub Singl ...

  2. android打包需要的图标

    ldpi:mdpi:hdpi:xhdpi:xxhdpi=3:4:6:8:12 大小: 32x32.png 48 72 96 144

  3. Vue之组件的生命周期

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 什么是session?

    Session一般译作会话.从不同的层面看待session,它有着类似但不全然相同的含义.比如,在web应用的用户看来,他打开浏览器访问一个电子商务网站,登录.并完成购物直到关闭浏览器,这是一个会话. ...

  5. CF-478C

    You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exa ...

  6. Django中对接第三方支付(支付宝)实现支付的流程

    1. 业务逻辑准备 1. 使用沙箱提供的商家环境 沙箱环境:是支付宝提供给开发者的模拟支付的环境 沙箱应用:https://docs.open.alipay.com/200/105311 沙箱账号:h ...

  7. LINUX:关于Redis集群的节点分配

    文章来源:http://www.cnblogs.com/hello-tl/p/7808268.html 根据上述  Redis集群搭建:http://www.cnblogs.com/hello-tl/ ...

  8. maven添加本地jar包到本地仓库

    1 进入jar包所在文件夹,进入cmd命令 2 执行命令 mvn install:install-file -Dfile=ojdbc6.jar -DgroupId=com.oracle -Dartif ...

  9. POJ 1144 Network (求割点)

    题意: 给定一幅无向图, 求出图的割点. 割点模板:http://www.cnblogs.com/Jadon97/p/8328750.html 分析: 输入有点麻烦, 用stringsteam 会比较 ...

  10. SHELL十三问[转载自CU论坛]

    原文地址:http://bbs.chinaunix.net/thread-218853-1-1.html 一.为什么称作shell? http://bbs.chinaunix.net/viewthr ...