poj 2653 线段与线段相交
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 11884 | Accepted: 4499 |
Description
Input
Output
The picture to the right below illustrates the first case from input.
Sample Input
5
1 1 4 2
2 3 3 1
1 -2.0 8 4
1 4 8 2
3 3 6 -2.0
3
0 0 1 1
1 0 2 1
2 0 3 1
0
Sample Output
Top sticks: 2, 4, 5.
Top sticks: 1, 2, 3.
/*
poj 2653 线段与线段相交 判断当前线段后面的线段是否与它相交即可 hhh-2016-05-04 22:10:50
*/
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <cstdio>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
const int maxn = 200000;
double eps = 1e-8;
int tot;
int n,m;
double x1,x2,y1,y2,x3,x4,y3,y4; int sgn(double x)
{
if(fabs(x) < eps) return 0;
if(x < 0)
return -1;
else
return 1;
} struct Point
{
double x,y;
Point() {}
Point(int _x,int _y)
{
x = _x,y = _y;
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const
{
return x*b.y-y*b.x;
}
}; struct Line
{
Point s,t;
Line() {}
Line(Point _s,Point _t)
{
s = _s;
t = _t;
}
int operator &(const Line&b)const
{
if( sgn((s-t) ^ (b.s-b.t)) == 0) //通过叉积判断
{
return 0;
}
return 1;
}
}; bool inter(Line l1,Line l2)
{
return
max(l1.s.x,l1.t.x) >= min(l2.s.x,l2.t.x) &&
max(l2.s.x,l2.t.x) >= min(l1.s.x,l1.t.x) &&
max(l1.s.y,l1.t.y) >= min(l2.s.y,l2.t.y) &&
max(l2.s.y,l2.t.y) >= min(l1.s.y,l1.t.y) &&
sgn((l2.s-l1.s)^(l1.t-l1.s))*sgn((l2.t-l1.s)^(l1.t-l1.s)) <= 0 &&
sgn((l1.s-l2.s)^(l2.t-l2.s))*sgn((l1.t-l2.s)^(l2.t-l2.s)) <= 0;
} int tans[maxn];
Line line[maxn]; int main()
{
while(scanf("%d",&n) && n)
{
memset(tans,1,sizeof(tans)); for(int i = 0; i < n; i++)
{
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
line[i] = Line(Point(x1,y1),Point(x2,y2));
}
int num = n;
for(int i = 0; i < n; i++)
{
for(int j = i+1; j < n; j++)
{
if(inter(line[i],line[j]))
{
tans[i] = 0;
num--;
break;
}
}
}
int cur = 0;
printf("Top sticks: ");
for(int i = 0; i < n; i++)
{
if(tans[i])
{
cur++;
if(num == cur)
printf("%d.\n",i+1);
else
printf("%d, ",i+1);
}
}
}
return 0;
}
poj 2653 线段与线段相交的更多相关文章
- POJ - 2653 - Pick-up sticks 线段与线段相交
判断线段与线段相交 莫名其妙的数据量 #include <iostream> #include <cstdio> #include <vector> #includ ...
- POJ 2653 Pick-up sticks(线段相交)
题意:给定n个木棍依次放下,要求最终判断没被覆盖的木棍是哪些. 思路:快速排斥以及跨立实验可以判断线段相交. #include<algorithm> #include<cstdio& ...
- POJ 2653 Pick-up sticks [线段相交 迷之暴力]
Pick-up sticks Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 12861 Accepted: 4847 D ...
- 线段相交 POJ 2653
// 线段相交 POJ 2653 // 思路:数据比较水,据说n^2也可以过 // 我是每次枚举线段,和最上面的线段比较 // O(n*m) // #include <bits/stdc++.h ...
- POJ 2653 - Pick-up sticks - [枚举+判断线段相交]
题目链接:http://poj.org/problem?id=2653 Time Limit: 3000MS Memory Limit: 65536K Description Stan has n s ...
- 线段和矩形相交 POJ 1410
// 线段和矩形相交 POJ 1410 // #include <bits/stdc++.h> #include <iostream> #include <cstdio& ...
- 判断线段和直线相交 POJ 3304
// 判断线段和直线相交 POJ 3304 // 思路: // 如果存在一条直线和所有线段相交,那么平移该直线一定可以经过线段上任意两个点,并且和所有线段相交. #include <cstdio ...
- poj 1269 线段与线段相交
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13605 Accepted: 60 ...
- POJ 1039 Pipe【经典线段与直线相交】
链接: http://poj.org/problem?id=1039 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
随机推荐
- Linux 复习
shift + control + + 终端窗口放大 control + - 终端窗口缩小 ls -alh > laowang.txt 重定向,并覆盖源文件内容 ls -alh >& ...
- 乐动力APP案例
第一部分 调研, 评测 下载软件并使用起来,描述最简单直观的个人第一次上手体验. 这款软件的主界面功能还是比较完善,里面有多个关于运动相关的数据,还有一些推荐健身教程,记录功能也十分不错,其中最难理解 ...
- python的模块和包
==模块== python语言的组织结构层次: 包->模块->代码文件->类->函数->代码块 什么是模块呢 可以把模块理解为一个代码文件的封装,这是比类更高一级的封装层 ...
- @SpringBootApplication 组合注解包含哪些注解及作用
序:在学习springboot,教程一般对一些注解语焉不详,发现@SpringBootApplication 这个注解包含了很多注解,也就是说使用这个注解可以少写几个注解,这里看源码粘出来一些,仅用于 ...
- 分布式版本控制系统Git的安装及使用
Git的安装分为客户端安装和服务端安装,鉴于我平时码代码在windows环境下,因此本文客户端安装直接在windows环境,服务端安装在linux环境下(centos). Git客户端安装 客户端下载 ...
- WebApi 的三种寄宿方式 (一)
最近逛博客园,看到了Owin,学习了一下,做个笔记,说不定将来哪天就用上了 关于 Owin 的介绍,百度解释的很清楚了: https://baike.baidu.com/item/owin/28607 ...
- 深入了解GOT,PLT和动态链接
之前几篇介绍exploit的文章, 有提到return-to-plt的技术. 当时只简单介绍了 GOT和PLT表的基本作用和他们之间的关系, 所以今天就来详细分析下其具体的工作过程. 本文所用的依然是 ...
- GIT入门笔记(5)- 创建版本库
版本库又名仓库,英文名repository,可以简单理解成一个目录, 这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能跟踪,以便任何时刻都可以追踪历史,或者在将来某个时刻 ...
- Groovy入门(2-2)Groovy的eclipse插件安装
1.安装eclipse插件 启动eclipse,点击help -> Install New Software... 在弹出的窗口中点击:Add... Groovy插件的地址:http://dis ...
- Python模块 - paramiko
paramiko模块提供了ssh及sft进行远程登录服务器执行命令和上传下载文件的功能.这是一个第三方的软件包,使用之前需要安装. 1 基于用户名和密码的 sshclient 方式登录 # 建立一个s ...