HDU4183_Pahom on Water
题意为给你若干个圆,每个圆的颜色对应一个频率,如果两个圆有公共部分,那么这两个圆之间可以走,你可以从起点开始,从频率小的圆走向频率大的圆并且到达终点后,从频率大的圆走向频率小的圆,最终回到起点,路径中每个圆只能走一次,是否存在一个满足条件的方案。
这样的,把红点当做起点,把紫点当做终点,如果两个圆相交,那么从频率小的圆连接一条边指向频率大的圆,边容量为1。如此一来,相当于求起点到终点的最大流量是否不小于2即可。因为只要不小于2,说明有两条不相交的路径达到终点,只要把其中的一条路径反向即可。
由于这里的最大流量可能很多,为了避免不必要的耗时,我们可以再找到两条路径后直接退出。更好实现的方法是跑两次EK,看看是否都能找到增广路就可以啦。
召唤代码君:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#define maxn 333
using namespace std; vector<int> v[maxn];
int c[maxn][maxn],pre[maxn],tag[maxn];
bool can[maxn];
int n,m,s,t,T,ans,N=1;
double hz[maxn];
int x[maxn],y[maxn],r[maxn];
int Q[maxn],bot,top; int dis(int x1,int y1,int x2,int y2)
{
return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
} void _init()
{
ans=0;
for (int i=1; i<=n; i++)
{
v[i].clear();
for (int j=1; j<=n; j++) c[i][j]=0;
}
for (int i=1; i<=n; i++)
{
scanf("%lf%d%d%d",&hz[i],&x[i],&y[i],&r[i]);
if (hz[i]==400) s=i;
if (hz[i]==789) t=i;
}
} void graph_build()
{
for (int i=1; i<=n; i++)
for (int j=1; j<=n; j++)
{
if (hz[j]<=hz[i]) continue;
if (dis(x[i],y[i],x[j],y[j])<(r[i]+r[j])*(r[i]+r[j]))
c[i][j]=1,v[i].push_back(j),v[j].push_back(i);
}
} bool EK(int TAG)
{
Q[bot=top=1]=s,tag[s]=TAG;
while (bot<=top)
{
int cur=Q[bot++];
for (unsigned i=0; i<v[cur].size(); i++)
if (tag[v[cur][i]]!=TAG && c[cur][v[cur][i]]>0)
{
tag[v[cur][i]]=TAG;
Q[++top]=v[cur][i];
pre[v[cur][i]]=cur;
if (v[cur][i]==t)
{
for (int k=t; k!=s; k=pre[k]) c[pre[k]][k]=0,c[k][pre[k]]=1;
return true;
}
}
}
return false;
} int main()
{
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
_init();
graph_build();
if (c[s][t])
{
puts("Game is VALID");
continue;
}
ans=1;
for (int i=1; i<=2; i++)
if (!EK(++N))
{
ans=0;
break;
}
if (ans) puts("Game is VALID");
else puts("Game is NOT VALID");
}
return 0;
}
HDU4183_Pahom on Water的更多相关文章
- [LeetCode] Pacific Atlantic Water Flow 太平洋大西洋水流
Given an m x n matrix of non-negative integers representing the height of each unit cell in a contin ...
- [LeetCode] Trapping Rain Water II 收集雨水之二
Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevati ...
- [LeetCode] Water and Jug Problem 水罐问题
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
- [LeetCode] Trapping Rain Water 收集雨水
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- [LeetCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- 如何装最多的水? — leetcode 11. Container With Most Water
炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...
- 【leetcode】Container With Most Water
题目描述: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...
- [LintCode] Trapping Rain Water 收集雨水
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- [LintCode] Container With Most Water 装最多水的容器
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
随机推荐
- 全面解析C#中的异步编程
当我们处理一些长线的调用时,经常会导致界面停止响应或者IIS线程占用过多等问题,这个时候我们需要更多的是用异步编程来修正这些问题,但是通常都是说起来容易做起来难,诚然异步编程相对于同步编程来说,它是一 ...
- Android #Android开发环境搭建
Android #Android开发环境搭建 1.下载:Google在国服的官网 https://developer.android.google.cn/index.html 1.点击首页 “ 获取 ...
- Activity启动过程中获取组件宽高的五种方式
第一种:(重写Activity的onWindowFocusChanged方法) /** * 重写Acitivty的onWindowFocusChanged方法 */ @Override public ...
- Django 前后端不分离 代码结构详解
Demo: hello_pycharm 根目录文件:hello_pycharm [__init__.py __pycache__ settings.py urls.py wsgi.py] A ...
- could not launch process: decoding dwarf section info at offset 0x0: too short
Fabric调试异常 作者在使用chaincode进行智能合约开发的过程中,使用Goland + Golang + win10_X64作为开发环境: GoLand 2018.1.4 Build #GO ...
- LAXCUS大数据操作系统3.03版本发布,欢迎使用试用
LAXCUS大数据操作系统3.03正式发布,欢迎下载使用试用.LAXCUS大数据操作系统,集成虚拟化.大数据.数据库.容器.中间件的多集群多用户多任务全栈通用系统软件,运行.开发.维护管理为一体的平台 ...
- 拒绝滥用golang defer机制
原文链接 : http://www.bugclosed.com/post/17 defer机制 go语言中的defer提供了在函数返回前执行操作的机制,在需要资源回收的场景非常方便易用(比如文件关闭, ...
- 配置Ubuntu16.04虚拟机 (用途:CTF_pwn)
因为学习需要16.xx的虚拟机,所以把之前18.04的Ubuntu卸掉重装了一遍Ubuntu16.04, 考虑到我有备份和重装系统的爱好,故记之,以备后用. 目录: //最后更新时间:190122·1 ...
- unset命令详解
基础命令学习目录首页 功能说明:unset是一个内建的Unix shell命令,在Bourne shell家族(sh.ksh.bash等)和C shell家族(csh.tcsh等)都有实现.它可以取消 ...
- Spring Cloud限流思路及解决方案
转自: http://blog.csdn.net/zl1zl2zl3/article/details/78683855 在高并发的应用中,限流往往是一个绕不开的话题.本文详细探讨在Spring Clo ...