题意:有n个水井,每个水井发出一些管线(都是线段),然后每条管线上最多只有一个水井。所有从不同的水井发出的管线的相交点都是清洁点(不存在清洁点是大于两条管线点的交点)。你需要在某些管线上放出一些机器人,它们会清洁所有该条管线上的清洁点。但是两条相交的管线不能同时放有机器人。问你是否存在一种可行的放机器人的方案。

将管线当成点,清洁点当作边(需要计算几何判断线段规范相交,具体看代码),建图,看看是否是二分图即可。

因为二分图显然可以选择一些点,使得每条边恰好被选择一个点(只选择X部或者只选择Y部的点就是一个合法解)。

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
struct Point{
ll x,y;
Point(const ll &x,const ll &y){
this->x=x;
this->y=y;
}
Point(){}
void read(){
scanf("%I64d%I64d",&x,&y);
}
}wells[1005];
typedef Point Vector;
Vector operator - (const Point &a,const Point &b){
return Vector(a.x-b.x,a.y-b.y);
}
ll Cross(const Vector &a,const Vector &b){
return a.x*b.y-a.y*b.x;
}
bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2)
{
double c1=Cross(a2-a1,b1-a1),c2=Cross(a2-a1,b2-a1),
c3=Cross(b2-b1,a1-b1),c4=Cross(b2-b1,a2-b1);
return c1*c2<=0 && c3*c4<=0;
}
int n,m;
struct PIPE{
int wid;
Point End;
PIPE(const int &wid,const Point &End){
this->wid=wid;
this->End=End;
}
PIPE(){}
PIPE(const int &wid,const ll &x,const ll &y){
this->wid=wid;
End.x=x;
End.y=y;
}
void read(){
scanf("%d",&wid);
End.read();
}
}pipes[1005];
bool cmp(const PIPE &a,const PIPE &b){
return a.wid<b.wid;
}
int v[2000005],first[1005],e,next[2000005];
void AddEdge(int U,int V){
v[++e]=V;
next[e]=first[U];
first[U]=e;
}
int col[1005];
bool dfs(int U,bool now)
{
for(int i=first[U];i;i=next[i]){
if(col[v[i]]==-1){
col[v[i]]=(now^1);
if(!dfs(v[i],now^1)){
return 0;
}
}
else if(col[v[i]]==col[U]){
return 0;
}
}
return 1;
}
int main(){
// freopen("c.in","r",stdin);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i){
wells[i].read();
}
for(int i=1;i<=m;++i){
pipes[i].read();
}
sort(pipes+1,pipes+m+1,cmp);
int sta;
for(int i=1;i<=m;++i){
if(pipes[i].wid!=pipes[i-1].wid){
sta=i;
}
if(pipes[i].wid!=pipes[i+1].wid){
for(int j=sta;j<=i;++j){
for(int k=i+1;k<=m;++k){
if(SegmentProperIntersection(wells[pipes[j].wid],pipes[j].End,wells[pipes[k].wid],pipes[k].End)){
AddEdge(j,k);
AddEdge(k,j);
}
}
}
}
}
memset(col,-1,sizeof(col));
for(int i=1;i<=m;++i){
if(col[i]==-1){
col[i]=0;
if(!dfs(i,0)){
puts("impossible");
return 0;
}
}
}
puts("possible");
return 0;
}

【计算几何】【二分图判定】Gym - 101485C - Cleaning Pipes的更多相关文章

  1. CF687A. NP-Hard Problem[二分图判定]

    A. NP-Hard Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. COJ 0578 4019二分图判定

    4019二分图判定 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给定一个具有n个顶点(顶点编号为0,1,… ...

  3. hdoj 3478 Catch(二分图判定+并查集)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3478 思路分析:该问题需要求是否存在某一个时刻,thief可能存在图中没一个点:将该问题转换为图论问题 ...

  4. UVA 11080 - Place the Guards(二分图判定)

    UVA 11080 - Place the Guards 题目链接 题意:一些城市.之间有道路相连,如今要安放警卫,警卫能看守到当前点周围的边,一条边仅仅能有一个警卫看守,问是否有方案,假设有最少放几 ...

  5. poj2942 Knights of the Round Table,无向图点双联通,二分图判定

    点击打开链接 无向图点双联通.二分图判定 <span style="font-size:18px;">#include <cstdio> #include ...

  6. HDU2444(KB10-B 二分图判定+最大匹配)

    The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  7. DFS的运用(二分图判定、无向图的割顶和桥,双连通分量,有向图的强连通分量)

    一.dfs框架: vector<int>G[maxn]; //存图 int vis[maxn]; //节点访问标记 void dfs(int u) { vis[u] = ; PREVISI ...

  8. bzoj4427【Nwerc2015】Cleaning Pipes清理管道

    题目描述 Linköping有一个相当复杂的水资源运输系统.在Linköping周围的出水点有一些水井.这些水通过管道输送到其它地点.每条管道是从某一个水井到城市的某个位置的直线管道. 所有管道在地下 ...

  9. UVa 11396 爪分解(二分图判定)

    https://vjudge.net/problem/UVA-11396 题意: 给出n个结点的简单无向图,每个点的度数均为3.你的任务是判断能否把它分解成若干爪.每条边必须属于一个爪,但同一个点可以 ...

随机推荐

  1. VC进度条的使用

    m_progress->GetPos(); //获取进度条的当前位置 m_progress->GetRange(int min,int max); //获取进度条控件的范围的下限和上限 m ...

  2. perl6 一个猜测密码的注入

    use HTTP::UserAgent; my $ua = HTTP::UserAgent.new; my $r = HTTP::Request.new; my $c = HTTP::Cookies. ...

  3. 64_p3

    perl-Locale-Msgfmt-0.15-17.fc26.noarch.rpm 12-Feb-2017 03:11 20558 perl-Locale-PO-0.27-6.fc26.noarch ...

  4. UVA题解二

    UVA题解二 UVA 110 题目描述:输出一个Pascal程序,该程序能读入不多于\(8\)个数,并输出从小到大排好序后的数.注意:该程序只能用读入语句,输出语句,if语句. solution 模仿 ...

  5. Python os模块和sys模块 操作系统的各种接口

    一.os模块 这个模块提供了一个便携式去使用操作系统的相关功能,如果只是想操作路径,请参阅os.path模块. ''' os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 ...

  6. python是如何进行内存管理的?

    Python内存管理机制 Python内存管理机制主要包括以下三个方面: 引用计数机制 垃圾回收机制 内存池机制 引用计数 举个例子说明引用是什么: 1 如上为一个简单的赋值语句,1就是对象,a就是引 ...

  7. SLD 官方实例

    基于xml标准的sld格式: <?xml version="1.0" encoding="UTF-8"?> <StyledLayerDescr ...

  8. google浏览器中,使用clockwork 来调试

    参考:https://laravel-china.org/courses/laravel-package/1976/debugging-tool-under-chrome-itsgoingdclock ...

  9. 关于VS2010的一些操作

    自动插入接口实现 1: class MyClass : IMyInterface 2: { 3:   4: } .csharpcode, .csharpcode pre { font-size: sm ...

  10. 学习笔记----float后不与前面元素同行解决办法。

    <li>文本<span> 16-08-17</span></li> 当非float的元素和float的元素在一起的时候(如上代码), 如果非float元 ...