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 ...
随机推荐
- spoolight on oracle 配置
spoolight seting 1ORACLE_HOME=D:\oracle\product\11.2.0\client_1set SQLPATH=D:\oracle\product\11.2.0\ ...
- 图像分类丨Inception家族进化史「GoogleNet、Inception、Xception」
引言 Google提出的Inception系列是分类任务中的代表性工作,不同于VGG简单地堆叠卷积层,Inception重视网络的拓扑结构.本文关注Inception系列方法的演变,并加入了Xcept ...
- SpringMVC对HTTP报文体的处理
客户端和服务端HTTP报文传递消息,而HTTP报文包含报文头和报文体.通常,解析请求参数以及返回页面都不需要我们关心HTTP报文体的读取和生成过程.但在某些特定场景下需要直接到请求报文中读取报文体, ...
- SQL Server开窗函数之OVER子句、PARTITION BY 子句
开窗函数与聚合函数一样,都是对行的集合组进行聚合计算.它用于为行定义一个窗口(这里的窗口是指运算将要操作的行的集合),它对一组值进行操作,不需要使用GROUP BY子句对数据进行分组,能够在同一行中同 ...
- C#/.net基础知识
1 .NET 中类和结构的区别? 答:结构和类具有大体的语法,但是结构受到的限制比类要多.结构不能申明有默认的构造函数,为结构的副本是又编译器创建 和销毁的,所以不需要默认的构造函数和析构函数.结构 ...
- ABAP事件分类
1.报表事件 INITIALIZATION. START-OF-SELECTION. END-OF-SELECTION. 2.选择屏幕事件 在INITIALIZATION和START-OF-SELEC ...
- Word通配符
通配符模式下: ^13表示回车,^32表示空格 第一步,使用通配符替换掉无关文本 M?G-C??[A-Z]{1,20}_[A-Z]{1,20}_201?????_?? VirtualTrial[0-9 ...
- ionic 2 起航 控件的使用 客户列表场景(四)
接下来,我们的客户列表要怎么刷新数据呢? 我们不会安卓开发,不会ios开发,没关系,我们还有ionic 2.ionic 2的控件 Ion-refresher 轻松帮我们搞掂. <!--下拉刷新- ...
- 小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载五(使用PhoneGap获取设备信息)
除了能够将HTML页面打包成可以直接安装运行的APP外,PhoneGap的一个最大优势在于可以通过JavaScript调用设备来访问设备上的硬件信息,从而实现一些原本只有依靠原生SDK才能够达到的目的 ...
- Android(java)学习笔记115:BroadcastReceiver之 Android广播机制
Android广播机制 android系统中有各式各样的广播,各种广播在Android系统中运行,当"系统/应用"程序运行时便会向Android注册各种广播.Android接收到广 ...