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). ...
随机推荐
- 初学者下载使用Python遇到的问题看它就行了
首先在python管网(www.python.org)中找到对应的版本与系统,以(window7系统64位python3.7.3为例) 打开电脑--打开浏览器--输入www.python.org--d ...
- allure2 report+ jenkins 使用
物色了一个挺漂亮的报告生成插件 ——allure. 下面介绍一下这个报告的使用. 1. 添加依赖 <dependencies> <!-- https://mvnrepository. ...
- SSH结合EasyUI系统(一)———简单介绍
鉴于前文<不仅仅是吐槽>,决定将自己学过的和在学的东西整理一下放进园子:做一个好园友! 接下来将会持续更新的是近一段时间在学的java web中比较流行的框架SSH(Struts+Spri ...
- InnoDB表优化
InnoDB表存储优化 适时的使用 OPTIMIZE TABLE 语句来重组表,压缩浪费的表空间.这是在其它优化技术不可用的情况下最直接的方法. OPTIMIZE TABLE 语句通过拷贝表数据并重建 ...
- PSO算法的改进(参数)
## 基本PSO的改进 虽然粒子群在求解优化函数时,表现了较好的寻优能力:通过迭代寻优计算,能够迅速找到近似解:但基本的PSO容易陷入局部最优,导致结果误差较大. 两个方面:1.将各种先进理论引入到P ...
- 4星|《财经》2018年第10期:远程视界自我定位为“专科远程医疗联合体O2O平台”,主要盈利模式就是做融资租赁
<财经>2018年第10期 总第527期 旬刊 本期主要内容:做远程医疗资金链断裂:人工智能时代有可能让刘易斯观点论失败:小米的盈利模式刨析:陆奇在百度的改革.其中1.4都成了朋友圈热文. ...
- 安装keystone时创建用户失败
系统:centos7.3 版本:openstack ocata 1.问题描述 安装keystone在创建用户时报错: The request you have made requires authen ...
- [Hanani]高数相关知识记录
分部积分 \(\int uv'{\rm d}x=uv-\int u'v{\rm d}x\)
- 暑假作业app博客
一.光照传感器 界面 简介 运用了传感器类,通过手机的感应区根据当时的光照强度显示出数据. 核心代码 protected void onCreate(Bundle savedInstanceState ...
- 第二阶段Sprint冲刺会议9
进展:查看有关“共享平台”的资料,看如何实现上传下载功能,并尝试编码,没有成功.