题意:

有n个圆,每个圆的中心和半径和一个频率都给定,只有一个频率最高的789为紫色,只有一个最低的400为红色,规则如下:

1.当两个圆严格相交时,且人是从红色到紫色的方向运动时可以由低频率向高频率移动

2.当两个圆严格相交时,且人是从紫色到红色的方向运动时可以由高频率向低频率运动

3.除了红色的圆以外,离开某个圆之后就会消失(即只能走一次)

思路:

如果一开始红色和紫色就相交,则存在合理方案。否则

本题要求是先从红点出发,经过紫点之后再返回红点,如果以红点作为源点,网络流算法不能先到达一个T,然后再到达另一个T,

所以不妨以紫点作为源点sp,红点作为tp,将点拆分成i和i+n,然后建边(i, i+n, 1), (sp, sp+n, 2)如果两个圆严格相交,设i的频率

大于j的频率,则(i+n, j, 1)反之(j+n, i, 1),求出最大流为2则存在合理方案。把S(紫色) -> T(红色)的两个流中的一个流反向,就可以形成一个

T -> S -> T的方案。

#include <bits/stdc++.h>
using namespace std; const int maxn = + ;
const int inf = 0x3f3f3f3f;
struct point{
double f;
double x, y, r;
} p[maxn];
struct edge{
int to, w, next;
} ed[maxn*maxn<<];
int k, n, sp, tp;
int head[maxn<<], tot, d[maxn<<], maxflow;
inline void init(){
memset( head, -, sizeof(head) );
tot = ;
} inline double getlen2( const point a, const point b ){
double x1 = a.x, x2 = b.x;
double y1 = a.y, y2 = b.y;
return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
} inline bool judge(point a, point b){
return getlen2(a, b) < (a.r+b.r)*(a.r+b.r);
} inline void add( int u, int v, int w ){
ed[++tot].to = v; ed[tot].w = w; ed[tot].next = head[u]; head[u] = tot;
ed[++tot].to = u; ed[tot].w = ; ed[tot].next = head[v]; head[v] = tot;
} inline bool bfs(){
memset( d, , sizeof(d) );
queue<int> q;
d[sp] = ;
q.push(sp);
while( !q.empty() ){
int x = q.front();
q.pop();
for( int i=head[x]; i!=-; i=ed[i].next ){
int y = ed[i].to;
if( ed[i].w && !d[y] ){
d[y] = d[x] + ;
q.push(y);
if( y==tp ) return ;
}
}
}
return ;
} inline int dfs( int x, int flow ){
if( x==tp ) return flow;
int res = flow, k;
for( int i=head[x]; i!=-&&res; i=ed[i].next ){
int y = ed[i].to;
if( ed[i].w && d[y]==d[x]+ ){
k = dfs( y, min( res, ed[i].w ) );
if(!k) d[y] = ;
ed[i].w -= k;
ed[i^].w += k;
res -= k;
}
}
return flow - res;
} inline void dinic(){
int flow = maxflow = ;
while( bfs() ){
while( flow = dfs(sp, inf) ) maxflow += flow;
}
} int main(){
// freopen("in.txt", "r", stdin);
scanf("%d", &k);
while( k-- ){
scanf("%d", &n);
init();
for( int i=; i<=n; i++ ){
scanf("%lf%lf%lf%lf", &p[i].f, &p[i].x, &p[i].y, &p[i].r);
if( p[i].f==400.0 ) tp = i;
else if( p[i].f==789.0 ) sp = i;
else add( i, i+n, );
}
if( judge( p[sp], p[tp] ) ){
puts("Game is VALID");
continue;
}
add( sp, sp+n, );
for( int i=; i<=n; i++ )
for( int j=i+; j<=n; j++ ){
if( judge(p[i], p[j]) ){
if( p[i].f<p[j].f ) add( j+n, i, );
else add( i+n, j, );
}
}
dinic();
// cout << maxflow << endl;
if( maxflow>= ) puts("Game is VALID");
else puts("Game is NOT VALID");
} return ;
}
/*
Game is NOT VALID
Game is VALID
*/

HDU4183 Pahom on Water(来回走最大流,一个点只经过一次)的更多相关文章

  1. HDU 4183 Pahom on Water(最大流SAP)

    Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  2. Pahom on Water(最大流)

    Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. hdoj 4183 Pahom on Water

    Pahom on Water Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. HDU 4183 Pahom on Water(最大流)

    https://vjudge.net/problem/HDU-4183 题意: 这道题目的英文实在是很难理解啊. 给出n个圆,每个圆有频率,x.y轴和半径r4个属性,每次将频率为400的圆作为起点,频 ...

  5. HDU 4183Pahom on Water(网络流之最大流)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4183 这题题目意思非常难看懂..我看了好长时间也没看懂..终于是从网上找的翻译. .我就在这翻译一下吧 ...

  6. 【HDOJ】4183 Pahom on Water

    就是一个网络流.red结点容量为2,查看最大流量是否大于等于2.对于条件2,把边反向加入建图.条件1,边正向加入建图. /* 4183 */ #include <iostream> #in ...

  7. 快速体验 Sentinel 集群限流功能,只需简单几步

    ️ Pic by Alibaba Tech on Facebook 集群限流 可以限制某个资源调用在集群内的总 QPS,并且可以解决单机流量不均导致总的流控效果不佳的问题,是保障服务稳定性的利器. S ...

  8. Doubles water!!!!!!只会水题怎么破

    Doubles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  9. 剑指XX(游戏10) - 走正步工厂一个安静的农场游戏的代码

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc2lsYW5ncXVhbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

随机推荐

  1. Java集合详解2:一文读懂Queue和LinkedList

    <Java集合详解系列>是我在完成夯实Java基础篇的系列博客后准备开始写的新系列. 这些文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查 ...

  2. 【2019年05月13日】A股ROE最高排名

    个股滚动ROE = 最近4个季度的归母净利润 / ((期初归母净资产 + 期末归母净资产) / 2). 查看更多个股ROE最高排名. 兰州民百(SH600738) - 滚动ROE:86.45% - 滚 ...

  3. Maven 教程(3)— Maven仓库介绍与本地仓库配置

    原文地址:https://blog.csdn.net/liupeifeng3514/article/details/79537837 1.Maven本地仓库/远程仓库的基本介绍 本地仓库是指存在于我们 ...

  4. mapreduce 变量共享

    mapreduce 全局变量共享 在编写MapReduce程序时,经常会遇到这样的问题,全局变量如何保存?如何让每个处理都能获取保存的这些全局变量?使用全局变量是不可避免的,但是 在MapRdeuce ...

  5. spring boot 源码解析52-actuate中MVCEndPoint解析

    今天有个别项目的jolokia的endpoint不能访问,调试源码发现:endpoint.enabled的开关导致的. 关于Endpoint, <Springboot Endpoint之二:En ...

  6. Python之路【第二十五篇】:数据库之pymysql模块

    数据库进阶 一.pymysql模块 pymysql是Python中操作Mysql的模块,其使用的方法和py2的MySQLdb几乎相同. 二.pymysql模块安装 pip install pymysq ...

  7. linux 1-常用命令

    文件处理命令: 命令格式:命令 [-选项] [参数] 例如:ls -la /etc   多个选项可以写在一起,不区分前后关系,例如 -l 和 -a 一起写成 -la 目录处理命令:ls (就是list ...

  8. 【题解】Largest Rectangle in a Histogram [SP1805] [POJ2559]

    [题解]Largest Rectangle in a Histogram [SP1805] [POJ2559] [题目描述] 传送: \(Largest\) \(Rectangle\) \(in\) ...

  9. 绝对有效 IntelliJ IDEA2019.2下载、安装及破解教程

        原文链接:https://blog.csdn.net/weixin_43904316/article/details/88881238                   https://bl ...

  10. 基于百度地图JavaScript API,员工住址统计

    公司一般都有通讯和住址的统计,但是文字化的表格根本就不知道住在哪. 用百度地图就可以轻松解决, 而且公司还经常人员变动,读取excel中的内容,就不用每次还要更改地图文件了. 在遇到需要聚餐在地图中标 ...