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. Openrisc的or1200

    1 什么是OpenRISC OpenRISC 是硬件开源社区opencores开发的RISC指令集处理器架构,包括32 bits 的Openrisc1000 和64 bitsOpenrisc 2000 ...

  2. Sql Server 2012 分页方法分析(offset and fetch)

    最近在分析 Sql Server 2012 中 offset and fetch 的新特性,发现 offset and fetch 无论语法的简洁还是功能的强大,都是相当相当不错的.其中  offse ...

  3. [Github筆記] 清除所有 Commit 紀錄

    # 把原來的 git 移除掉 sudo rm .git -r # 初始化 git init git remote add origin https://github.com/username/repo ...

  4. 原创 齐天大圣老司机亲传rescue恢复磁盘分区

    老葵花哥哥课堂开课了本文档秉承爱看不看的原则 一不要钱 二服务大众的高尚情操咱们今天讲一讲rescue恢复磁盘分区 首先咱们搭建环境搞起来 (parted) mkpart #创建分区 Partitio ...

  5. ios之UITextfield (2)

    UItextField通常用于外部数据输入,以实现人机交互.下面以一个简单的登陆界面来讲解UItextField的详细使用. //用来显示“用户名”的label UILabel* label1 = [ ...

  6. Manjaro/Arch linux 安装输入法

    输入命令: sudo pacman -Syu fcitx fcitx-googlepinyin fcitx-im fcitx-configtool 编辑 ~/.xprofile:# xfcitxexp ...

  7. VS C++项目报错warning C4199: ……use /Zc:twoPhase-

    具体的报错如下: c1xx : warning C4199: two-phase name lookup is not supported for C++/CLI, C++/CX, or OpenMP ...

  8. Hibernate-03

    目的:表操作(表维护) 一.一对一(略过) 二.一对 1.建表原则:在多的一方创建外键指向一的一方的外键 2.建表:实体中添加 商品实体表: private Set<User> user ...

  9. 3. COLLATIONS

    3. COLLATIONS 表COLLATIONS提供有关每个字符集排序规则的信息.下表中SHOW Name对应SHOW COLLATION. INFORMATION_SCHEMA Name SHOW ...

  10. pwnable flag之write up

    Papa brought me a packed present! let's open it. Download : http://pwnable.kr/bin/flag This is rever ...