【计算几何】【二分图判定】Gym - 101485C - Cleaning Pipes
题意:有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的更多相关文章
- CF687A. NP-Hard Problem[二分图判定]
A. NP-Hard Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- COJ 0578 4019二分图判定
4019二分图判定 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 给定一个具有n个顶点(顶点编号为0,1,… ...
- hdoj 3478 Catch(二分图判定+并查集)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3478 思路分析:该问题需要求是否存在某一个时刻,thief可能存在图中没一个点:将该问题转换为图论问题 ...
- UVA 11080 - Place the Guards(二分图判定)
UVA 11080 - Place the Guards 题目链接 题意:一些城市.之间有道路相连,如今要安放警卫,警卫能看守到当前点周围的边,一条边仅仅能有一个警卫看守,问是否有方案,假设有最少放几 ...
- poj2942 Knights of the Round Table,无向图点双联通,二分图判定
点击打开链接 无向图点双联通.二分图判定 <span style="font-size:18px;">#include <cstdio> #include ...
- HDU2444(KB10-B 二分图判定+最大匹配)
The Accomodation of Students Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- DFS的运用(二分图判定、无向图的割顶和桥,双连通分量,有向图的强连通分量)
一.dfs框架: vector<int>G[maxn]; //存图 int vis[maxn]; //节点访问标记 void dfs(int u) { vis[u] = ; PREVISI ...
- bzoj4427【Nwerc2015】Cleaning Pipes清理管道
题目描述 Linköping有一个相当复杂的水资源运输系统.在Linköping周围的出水点有一些水井.这些水通过管道输送到其它地点.每条管道是从某一个水井到城市的某个位置的直线管道. 所有管道在地下 ...
- UVa 11396 爪分解(二分图判定)
https://vjudge.net/problem/UVA-11396 题意: 给出n个结点的简单无向图,每个点的度数均为3.你的任务是判断能否把它分解成若干爪.每条边必须属于一个爪,但同一个点可以 ...
随机推荐
- 【leetcode 简单】第四十题 求众数
给定一个大小为 n 的数组,找到其中的众数.众数是指在数组中出现次数大于 ⌊ n/2 ⌋ 的元素. 你可以假设数组是非空的,并且给定的数组总是存在众数. 示例 1: 输入: [3,2,3] 输出: 3 ...
- Django之动态验证码的生成
kind.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- Openflow Plugin学习笔记1
主入口 ConfigurableOpenFlowProviderModule是OpenFlowPlugin中启动加载的入口,如下: @Override public java.lang.AutoClo ...
- 使用maven打包项目遇到错误: http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
今天在使用maven打包项目时遇到一个错误: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin ...
- Linux内核多线程实现方法 —— kthread_create函数【转】
转自:http://blog.csdn.net/sharecode/article/details/40076951 Linux内核多线程实现方法 —— kthread_create函数 内核经常需要 ...
- SQL 变量 条件查询 插入数据
(本文只是总结网络上的教程) 在操作数据库时 SQL语句中难免会用到变量 比如 在條件值已知的情況下 INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值 ...
- tracert和traceroute使用
Traceroute提取发 ICMP TTL到期消息设备的IP地址并作域名解析.每次 ,Traceroute都打印出一系列数据,包括所经过的路由设备的域名及 IP地址,三个包每次来回所花时间. 转自 ...
- Android 反编译神器jadx的使用
一.前言 今天介绍一个非常好用的反编译的工具 jadx .jadx 的功能非常的强大,对我而言,基本上满足日常反编译需求. jadx 优点: 图形化的界面. 拖拽式的操作. 反编译输出 Java 代码 ...
- centos7安装Python3的过程中会和Python2.7版本冲突导致yum版本比对应,致使yum不能使用的问题。
centos7安装Python3的过程中会和Python2.7版本冲突导致yum版本比对应,致使yum不能使用的问题. 原因:yum调用Python,启动程/usr/bin/yum就是一个python ...
- bash: composer: command not found
下载composer到本地:curl -sS https://getcomposer.org/installer | php 移动至系统服务:sudo mv composer.phar /usr/bi ...