题意:有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. 【译】DTD - Entities

    原文:DTD - Entities 实体用于定义XML文档中特殊字符的快捷方式. 实体主要有四种类型: 内置实体(Built-in entities) 字符实体(Character entities) ...

  2. 2017 ACM暑期多校联合训练 - Team 4 1007 HDU 6073 Matching In Multiplication (模拟)

    题目链接 Problem Description In the mathematical discipline of graph theory, a bipartite graph is a grap ...

  3. unity3d 资源文件从MAX或者MAYA中导出的注意事项

    unity3d 资源文件从MAX或者MAYA中导出的注意事项     1.首先,Unity3d 中,导出带动画的资源有2种导出方式可以选择:    1) 导出资源时,只导出一个文件,保留模型,骨骼和所 ...

  4. windows程序设计.第一个windos程序

    Windows程序设计(第5版) windows程序需要调用API. 第一个Windows程序 /*HelloMsg.c -- Displays "Hello World!" in ...

  5. 大数加法(SDUT“斐波那契”串)4335

    题目链接:https://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Contest/contestproblem/cid/2697/pid/4335.ht ...

  6. Sqlmap注入技巧收集整理

    TIP1 当我们注射的时候,判断注入 http://site/script?id=10http://site/script?id=11-1 # 相当于 id=10http://site/script? ...

  7. php常用表单验证类用法实例

    <?php /** * 页面作用:常用表单验证类 * 作 者:欣然随风 * QQ:276624915 */ class class_post { //验证是否为指定长度的字母/数字组合 func ...

  8. python简单爬虫(二)

    上一篇简单的实现了获取url返回的内容,在这一篇就要第返回的内容进行提取,并将结果保存到html中. 一 . 需求: 抓取主页面:百度百科Python词条   https://baike.baidu. ...

  9. PHP扩展插件 imagick 、PDO_MYSQL 安装

    环境准备 echo $LC_ALL echo "export LC_ALL=C" >> /etc/profile source /etc/profile yum ins ...

  10. cin关闭同步[转]

    很多人会说cin的速度比scanf慢很多, 其实不然. cin慢的原因主要在于默认cin与stdin总是保持同步, 这一步是消耗时间大户. 只需要加上ios::sync_with_stdio(fals ...