题意为给你若干个圆,每个圆的颜色对应一个频率,如果两个圆有公共部分,那么这两个圆之间可以走,你可以从起点开始,从频率小的圆走向频率大的圆并且到达终点后,从频率大的圆走向频率小的圆,最终回到起点,路径中每个圆只能走一次,是否存在一个满足条件的方案。

这样的,把红点当做起点,把紫点当做终点,如果两个圆相交,那么从频率小的圆连接一条边指向频率大的圆,边容量为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的更多相关文章

  1. [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 ...

  2. [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 ...

  3. [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 ...

  4. [LeetCode] Trapping Rain Water 收集雨水

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  5. [LeetCode] Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...

  6. 如何装最多的水? — leetcode 11. Container With Most Water

    炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...

  7. 【leetcode】Container With Most Water

    题目描述: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ...

  8. [LintCode] Trapping Rain Water 收集雨水

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  9. [LintCode] Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).  ...

随机推荐

  1. Laravel 跨框架队列交互

    公司大部分项目是laravel框架,但有些是yii框架,这两个框架之间有消息需要通信,比如在yii框架发布消息,laravel框架中的队列去处理,用redis作为消息连接纽带 laravel 队列原理 ...

  2. 一句话打印'*'图案(列表推导式, 人生苦短, 我用Python)

    ```python # coding=utf-8 print ('\n'.join(['*'*6 for i in range(4)])) # ****** # ****** # ****** # * ...

  3. c++三大概念要分清--重载,隐藏(重定义),覆盖(重写)

    重载,隐藏(重定义),覆盖(重写)—这几个名词看着好像很像,不过其实一样都不一样!! 综述: 说明:覆盖中的访问修饰符可以不同是指可以不用显示地用virtual:当访问修饰符改为const或者stat ...

  4. 编写webpack 插件

    Webpack插件为第三方开发者释放了Webpack的最大可能性.利用多级回调开发者可以把他们自己的需要的功能引入到Webpack里面来.Build插件比Build loader 更进一步.因为你需要 ...

  5. python如何与以太坊交互并将区块链信息写入SQLite

    关于区块链介绍性的研讨会通常以易于理解的点对点网络和银行分类账这类故事开头,然后直接跳到编写智能合约,这显得非常突兀.因此,想象自己走进丛林,想象以太坊区块链是一个你即将研究的奇怪生物.今天我们将观察 ...

  6. hive对于lzo文件处理异常Caused by: java.io.IOException: Compressed length 842086665 exceeds max block size 67108864 (probably corrupt file)

    hive查询lzo数据格式文件的表时,抛 Caused by: java.io.IOException: Compressed length 842086665 exceeds max block s ...

  7. BugPhobia贡献篇章:团队贡献分值与转会确定

    0x01 :无言 0x02 :团队贡献分说明 (1202)冯志睿 54 (1156)李入云 43 (1188)李云涛 56 (1184)马腾跃 26 (1197)钱林琛 60 (1100)王鹿鸣 63 ...

  8. Daily Srum 10.26

    Daily Scrum Meeting 虽然TFS的相关使用已经在上面贴出来一段时间,但是要运用TFS还是有些困难的,特别是TFS的代码管理机制,所以我们让部分人先弄清楚,然后再教授给其他人.终于大家 ...

  9. 5233杨光--Linux第二次实验

    实验说明 1. 环境登录 无需密码自动登录,系统用户名shiyanlou,密码shiyanlou 若不小心登出后,直接刷新页面即可 2. 环境使用 完成实验后可以点击桌面上方的“实验截图”保存并分享实 ...

  10. mysql 官方集群

    一.环境准备(Centos7,mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz) 卸载以前安装的Mysql 或者 mariadb yum -y ...