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

这样的,把红点当做起点,把紫点当做终点,如果两个圆相交,那么从频率小的圆连接一条边指向频率大的圆,边容量为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. 彻底搞清楚python字符编码

    在讨论python编码之前,我先了解了几种编码的由来. 一.编码类型 1.ascci码 ascci码由美国人发明,用1个字节(byte)存储英文和字符,前期用了128个,后来新加了其他欧洲国家的符号, ...

  2. Qt-网易云音乐界面实现-5 收藏列表,播放列表实现 QListWidget QTableWidget

    先上目前完成的内容吧,发现后面越写越多.在看看点击量,心凉凉. 完成了左侧的导航列表,还有就是右下角的播放列表. //创建的歌单 my_Create_Music_List = new QListWid ...

  3. 转载Linux下开启MySQL日志

    转载https://blog.csdn.net/weixin_38187469/article/details/79273962 开启mysql日志   1.查看日志是否启用 mysql> sh ...

  4. charles抓包https/模拟弱网/设置断点重定向/压测

    charles几个常用功能   1,ios 抓包https网页:(如未配置,会显示unknown) 第一步是:给手机安装SSL证书 手机和电脑在同一wifi下,手机wifi配置http代理,ip是电脑 ...

  5. shentou mianshiti

    给你一个网站你是如何来渗透测试的? 在获取书面授权的前提下.1)信息收集,1,获取域名的whois信息,获取注册者邮箱姓名电话等.2,查询服务器旁站以及子域名站点,因为主站一般比较难,所以先看看旁站有 ...

  6. SNMP TRAP报文解析

    转载地址: https://blog.csdn.net/eric_sunah/article/details/19557683 SNMP的报文格式 SNMP代理和管理站通过SNMP协议中的标准消息进行 ...

  7. IO多路复用多并发服务器模板

    import socket import selectors # IO多路复用选择器 epoll_selector = selectors.EpollSelector() # 实例化选择器 serve ...

  8. Git知识点整合

    Git安装 Windows上安装Git 64 位安装包下载地址 : https://github.com/git-for-windows/git/releases/download/v2.16.2.w ...

  9. FFMS2 官方说明译文 [原创]

    原文:https://github.com/FFMS/ffms2 译文:http://www.cnblogs.com/popapa/p/ffms2.html 采集日期:2018-3-18 FFmpeg ...

  10. 分享一篇IBN(Intent-based networking)调研报告

    IBN调研报告 背景 SDN(Software-defined network):最大特点在于具有松耦合的控制平面与数据平面.支持集中化的网络状态控制.实现底层网络设施对上层应用的透明.具有灵活的软件 ...