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 ...
随机推荐
- Linux学习笔记——如何使用echo指令向文件写入内容
0.前言 本文总结如何使用echo命令向文件中写入内容,例如使用echo指令覆盖文件内容,使用echo指令向文件追加内容,使用echo指令往文件中追加制表符. echo向文件中输出内容 ...
- 利用Vagrant and VirtualBox搭建core os环境
利用Vagrant and VirtualBox搭建core os环境 系统环境 ubuntu 14.04 x64 vagrant 1.7.4 virtualbox 4.3.10 git 1.9.1 ...
- 移动端之js控制rem,适配字体
方法一:设置fontsize 按照iphone 5的适配 1em=10px 适配320 // “()()”表示自执行函数 (function (doc, win) { var docEl = ...
- 现阶段github上的emysql编译无法通过的问题
最近在写db引擎,今天用到了emysql,找到https://github.com/Eonblast/Emysql,拽下来,然后发现竟然编译不通过~~去网上找了下资料,在 http://erlang. ...
- ThreadLocal源码解析,内存泄露以及传递性
我想ThreadLocal这东西,大家或多或少都了解过一点,我在接触ThreadLocal的时候,觉得这东西很神奇,在网上看了很多博客,也看了一些书,总觉得有一个坎跨不过去,所以对ThreadLoca ...
- Android Studio maven-metadata.xml 卡着不动原因和解决方法
头一天好好的,第二天就卡着了. 一直在这个地方不动,如果停止就会报 Error:Could not run build action using Gradle distribution ‘https: ...
- Centos离线安装Docker并加入到Swarm管理节点
以root用户登录 加入Swarm前需要在Swarm上生成Token,所以需要提前将Swarm集群搭建完成后,再运行以下命令将各虚机加入到swarm节点 下载docker离线安装包,并拷贝到/root ...
- CentOS 7安装Docker服务详细过程
---恢复内容开始--- Docker 简介 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟 ...
- SharePoint 2013 安装配置(1)
在这篇文章中,我将逐步介绍在Windows Server 2012 R2上安装SharePoint 2013. 在进一步详细介绍之前,让我们先了解SharePoint 2013安装的硬件和软件要求.您 ...
- Spark Job调优(Part 1)
原文链接:https://wongxingjun.github.io/2016/05/11/Spark-Job%E8%B0%83%E4%BC%98-Part-1/ Spark应用的执行效率是所有程序员 ...