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). ...
随机推荐
- SSIS 处理错误的方法
Package在执行过程中,不可避免地会发生错误,如果处理错误?简单粗暴的做法,是Package直接停止运行.对于一个成熟的ETL工具,这显然不是唯一的错误处理方法.如果在数据流中出现错误,那么数据流 ...
- 【总结】浅谈ref与out
ref——仅仅是一个地址 (1)当一个方法或函数在使用ref作为参数时,在方法中或函数中对ref参数所做的更改都将反映在该变量中. (2)如果要使用ref参数,则必须将参数作为ref显示传递到方法中. ...
- 网易公开课[一万分钟]《office办公达人养成计划》
note: Shift表示移动 Ctrl表示复制 Excel: 快速选中单元格: 选中表格左上角Ctrl+A Ctrl+方向键,跳到行或列的尽头 Ctrl+Shift+方向键,选中一行或一列 Shif ...
- [环境配置]Ubuntu16.04下编译安装gcc6.3.0
上一篇的SVS要用gcc6.3编译,否则结果不正确,本来以为gcc很好装,结果发现用apt-get安装gcc6只能安装6.5版本,代码作者奇特的要求只能用gcc6.3,没办法只能用源码装了,期间碰见了 ...
- jmeter阶梯加压线程组
添加阶梯加压线程组路径为鼠标捕获测试计划后,点击鼠标右键->添加->Threads(Users)->jp@gc – Stepping Thread Group(deprecated) ...
- 小强版之无码理解C语言指针
1. 先从普通变量开始 2. 撸完变量撸指针 3. 故事情节进一步发展,此处少儿不宜 4. 奶茶妹妹捉奸,小强死定了 5. 源码欣赏 #include <stdio.h> ...
- 匹配追踪算法(MP)简介
图像的稀疏表征 分割原始图像为若干个\[\sqrt{n} \times \sqrt{n}\]的块. 这些图像块就是样本集合中的单个样本\(y = \mathbb{R}^n\). 在固定的字典上稀疏分解 ...
- Netty源码分析第3章(客户端接入流程)---->第4节: NioSocketChannel注册到selector
Netty源码分析第三章: 客户端接入流程 第四节: NioSocketChannel注册到selector 我们回到最初的NioMessageUnsafe的read()方法: public void ...
- MUI的踩坑笔记
最近在做公司项目的手机端实现,稍微记录下遇到的坑 1.在app开发中,若要使用HTML5+扩展api,必须等plusready事件发生后才能正常使用,mui将该事件封装成了mui.plusReady( ...
- thinkphp 3.x下的任意文件包含(有条件)分析
漏洞原理 实现自己的模版引擎不当,在模版渲染的情况下存在任意变量覆盖漏洞.. 漏洞详情 漏洞位置1 ThinkPHP/Library/Think/View.class.php 需要修改配置文件 指定T ...