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. CATransaction 知识

    CATransaction 事务类,可以对多个layer的属性同时进行修改.它分隐式事务,和显式事务. 区分隐式动画和隐式事务:隐式动画通过隐式事务实现动画 . 区分显式动画和显式事务:显式动画有多种 ...

  2. Node.js Addons翻译(C/C++扩展)

    PS:请先升级Node 6.2.1,Node 升级命令 npm install -g n;n stable.NOde.js扩展是一个通过C/C++编写的动态链接库,并通过Node.js的函数requi ...

  3. find、filter、map的区别

    1.find 查询数组中符合条件的第一个元素,如果没有符合条件的元素则返回空数组 ,,,,,,] ) var men=[ {name:',sex:'女'}, {name:',sex:'nan'}, { ...

  4. python基础一 day6 文件操作

    读写只会进行两步, r+模式下写读 seek是按字节去找的 for line in f: for循环是一行一行的读取出来 strip默认去空格和换行符 空格.制表符.换行符.回车.换页垂直制表符和换行 ...

  5. Spring框架针对dao层的jdbcTemplate操作crud之update修改数据库操作

    使用jdbcTemplate 原理是把加载驱动Class.forName("com.mysql.jdbc.Driver"); 和连接数据库Connection conn=Drive ...

  6. vue的使用配置

    我的编辑器是webstorm,虽然占内容占资源, 但是用起来很方便, 刚开始接触的时候就是用这个软件,很喜欢. vue的教程 1.http://www.jianshu.com/p/5ba253651c ...

  7. kvm的4中网络模型(qemu-kvm)

    1. 隔离模式(类似vmare中仅主机模式):虚拟机之间组建网络,该模式无法与宿主机通信,无法与其他网络通信,相当于虚拟机只是连接到一台交换机上,所有的虚拟机能够相互通信. 2. 路由模式:相当于虚拟 ...

  8. maven构建springmvc项目

    1.Eclipse中 NEW ->OTHER->Maven->maven project 2.选择项目路径 3.选择项目类型->next->输入groupid和artif ...

  9. 【BZOJ 2431】 [HAOI2009] 逆序对数列 (DP)

    Description 对于一个数列{ai},如果有iaj,那么我们称ai与aj为一对逆序对数.若对于任意一个由1~n自然数组成的 数列,可以很容易求出有多少个逆序对数.那么逆序对数为k的这样自然数数 ...

  10. reactNative 介绍

    React Native (简称RN)是Facebook于2015年4月开源的跨平台移动应用开发框架,是Facebook早先开源的UI框架 React 在原生移动应用平台的衍生产物,目前支持iOS和安 ...