Jack Straws POJ - 1127 (几何计算)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 5428 | Accepted: 2461 |
Description
Input
When n=0,the input is terminated.
There will be no illegal input and there are no zero-length straws.
Output
Sample Input
7
1 6 3 3
4 6 4 9
4 5 6 7
1 4 3 5
3 5 5 5
5 2 6 3
5 4 7 2
1 4
1 6
3 3
6 7
2 3
1 3
0 0 2
0 2 0 0
0 0 0 1
1 1
2 2
1 2
0 0 0
Sample Output
CONNECTED
NOT CONNECTED
CONNECTED
CONNECTED
NOT CONNECTED
CONNECTED
CONNECTED
CONNECTED
CONNECTED 题意:问两条线段是否连通,通过第三条线段连通也算连通
题解:几何计算的模版加并查集,用floyd算法应该也可以吧
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=;
const double eps=1e-; //考虑误差的加法运算
double add(double x,double y)
{
if(abs(x+y)<eps*(abs(x)+abs(y)))
return ;
return x+y;
} //二维向量结构体
struct P
{
double x,y;
P() {}
P(double x,double y):x(x),y(y){}
P operator+(P p)
{
return P(add(x,p.x),add(y,p.y));
}
P operator-(P p)
{
return P(add(x,-p.x),add(y,-p.y));
}
P operator*(double d)
{
return P(x*d,y*d);
}
double dot(P p) //内积
{
return add(x*p.x,y*p.y);
}
double det (P p) //外积
{
return add(x*p.y,-y*p.x);
}
}; //判断点是否在直线上
bool on_seg(P p1,P p2,P q)
{
return (p1-q).det(p2-q)== && (p1-q).dot(p2-q)<=;
} //计算直线p1-p2与直线q1-q2的交点
P inter(P p1,P p2,P q1,P q2)
{
return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));
} int n;
P p[maxn],q[maxn]; //保存一条线段的两个端点
bool G[maxn][maxn]; //线段之间是否联通的图 int main()
{
while(cin>>n && n)
{
memset(G,false,sizeof(G));
for(int i=;i<n;i++)
cin>>p[i].x>>p[i].y>>q[i].x>>q[i].y; for(int i=;i<n;i++)
for(int j=;j<n;j++)
{
if((p[i]-q[i]).det(p[j]-q[j])==)
{
G[i][j]=G[j][i]=on_seg(p[i], q[i], p[j])
|| on_seg(p[i], q[i], q[j])
|| on_seg(p[j], q[j], p[i])
|| on_seg(p[j], q[j], q[i]);
}
else
{
P r=inter(p[i], q[i], p[j], q[j]);
G[i][j]=G[j][i]=on_seg(p[i], q[i], r) && on_seg(p[j], q[j], r);
}
} for(int k=;k<n;k++)
for(int i=;i<n;i++)
for(int j=;j<n;j++)
G[i][j] |=G[i][k] && G[k][j];
int x,y;
while(cin>>x>>y && (x||y))
{
x--;
y--;
if(G[x][y])
cout<<"CONNECTED"<<endl;
else
cout<<"NOT CONNECTED"<<endl;
}
}
return ;
}
Jack Straws POJ - 1127 (几何计算)的更多相关文章
- Jack Straws POJ - 1127 (简单几何计算 + 并查集)
In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table ...
- Jack Straws(POJ 1127)
原题如下: Jack Straws Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5555 Accepted: 2536 ...
- Jack Straws(poj 1127) 两直线是否相交模板
http://poj.org/problem?id=1127 Description In the game of Jack Straws, a number of plastic or wood ...
- poj 1127:Jack Straws(判断两线段相交 + 并查集)
Jack Straws Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2911 Accepted: 1322 Descr ...
- poj 1127 -- Jack Straws(计算几何判断两线段相交 + 并查集)
Jack Straws In the game of Jack Straws, a number of plastic or wooden "straws" are dumped ...
- poj1127 Jack Straws(线段相交+并查集)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Jack Straws Time Limit: 1000MS Memory L ...
- 1840: Jack Straws
1840: Jack Straws 时间限制(普通/Java):1000MS/10000MS 内存限制:65536KByte 总提交: 168 测试通过:129 描述 I ...
- TZOJ 1840 Jack Straws(线段相交+并查集)
描述 In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the ta ...
- 1549: Navigition Problem (几何计算+模拟 细节较多)
1549: Navigition Problem Submit Page Summary Time Limit: 1 Sec Memory Limit: 256 Mb Su ...
随机推荐
- java wait(),notify(),notifyAll()
wait()的作用是使当前执行代码的线程进行等待,此方法是Object类的方法,该方法用来将当前线程置入“预执行队列”中,并且在wait()所带的代码处停止执行,直到接到通知或被中断位置.在调用wai ...
- c#基础值类和引用类型
//值类型:int double char decimal bool enum struct //引用类型:string 数组 自定义类 集合 object 接口 值传递传递的值得本身 引用传递传递的 ...
- I/O操做总结(四))
前面已经把java io的主要操作讲完了 这一节我们来说说关于java io的其他内容 Serializable序列化 实例1:对象的序列化 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
- Angular 路由route实例
iSun Design & Code AngularJS - 路由 routing 基础示例 AngularJS 路由 routing 能够从页面的一个视图跳转到另外一个视图,对单页面应用来讲 ...
- ios获取数据之encodeURI 和 decodeURI
在APP开发过程中,免不了要进行ios的数据处理,在ios传递数据的过程中,会出现JSON数据获取不到的情况,这时候就轮到encodeURI 和 decodeURI出马了. 1.encodeURI,d ...
- MyBatis关联查询、多条件查询
MyBatis关联查询.多条件查询 1.一对一查询 任务需求; 根据班级的信息查询出教师的相关信息 1.数据库表的设计 班级表: 教师表: 2.实体类的设计 班级表: public class Cla ...
- C# List的使用
1.所需引入的命名空间: using System.Collections.Generic; 2.初始化 [1]空: List<int> list = new List<int> ...
- javaSe-字符型和布尔型
其实java数据类型一节就可以全部写完了,为什么还需要字符型和布尔型呢,原因是这俩个都很重要: 字符型用char表示,字符分三种: 普通字符:char a = 'a',普通字符表示一个普通的字符,没有 ...
- [机器视觉] SIFT特征-尺度不变特征理解
SIFT特征-尺度不变特征理解 简介 SIFT,即尺度不变特征变换(Scale-invariant feature transform,SIFT),是用于图像处理领域的一种描述.这种描述具有尺度不变性 ...
- 什么样子的WordPress网站更受搜索引擎欢迎
网站的导航功能对于搜索引擎而言是非常重要的 网站的导航功能对于帮助用户迅速找到他们想要的内容来说是很重要的.它对帮助搜索引擎理解该网站有哪些重要内容同样非常重要.虽然百度的搜索结果都是指向每一个特定的 ...