poj 3498 March of the Penguins(拆点+枚举汇点 最大流)
Time Limit: 8000MS | Memory Limit: 65536K | |
Total Submissions: 4873 | Accepted: 2220 |
Description
Somewhere near the south pole, a number of penguins are standing on a number of ice floes. Being social animals, the penguins would like to get together, all on the same floe. The penguins do not want to get wet, so they have use their limited jump distance to get together by jumping from piece to piece. However, temperatures have been high lately, and the floes are showing cracks, and they get damaged further by the force needed to jump to another floe. Fortunately the penguins are real experts on cracking ice floes, and know exactly how many times a penguin can jump off each floe before it disintegrates and disappears. Landing on an ice floe does not damage it. You have to help the penguins find all floes where they can meet.

A sample layout of ice floes with 3 penguins on them.
Input
On the first line one positive number: the number of testcases, at most 100. After that per testcase:
One line with the integer N (1 ≤ N ≤ 100) and a floating-point number D (0 ≤ D ≤ 100 000), denoting the number of ice pieces and the maximum distance a penguin can jump.
N lines, each line containing xi, yi, ni and mi, denoting for each ice piece its X and Y coordinate, the number of penguins on it and the maximum number of times a penguin can jump off this piece before it disappears (−10 000 ≤ xi, yi ≤ 10 000, 0 ≤ ni ≤ 10, 1 ≤ mi ≤ 200).
Output
Per testcase:
- One line containing a space-separated list of 0-based indices of the pieces on which all penguins can meet. If no such piece exists, output a line with the single number −1.
Sample Input
2
5 3.5
1 1 1 1
2 3 0 1
3 5 1 1
5 1 1 1
5 4 0 1
3 1.1
-1 0 5 10
0 0 3 9
2 0 1 1
Sample Output
1 2 4
-1
Source
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string.h>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<cmath>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const double PI=acos(-1.0);
const double eps=0.0000000001;
const int INF=1e9;
const int N=+;
int b[N];
int head[N];
int tot;
struct node{
int to,next,flow;
}edge[N<<];
struct Node{
double x,y;
int m,k;
}a[N];
void init(){
memset(head,-,sizeof(head));
tot=;
}
void add(int u,int v,int flow){
edge[tot].to=v;
edge[tot].flow=flow;
edge[tot].next=head[u];
head[u]=tot++; edge[tot].to=u;
edge[tot].flow=;
edge[tot].next=head[v];
head[v]=tot++;
}
int dis[N];
int BFS(int s,int t){
queue<int>q;
memset(dis,-,sizeof(dis));
q.push(s);
dis[s]=;
while(!q.empty()){
int x=q.front();
q.pop();
if(x==t)return ;
for(int i=head[x];i!=-;i=edge[i].next){
int v=edge[i].to;
if(dis[v]==-&&edge[i].flow){
dis[v]=dis[x]+;
q.push(v);
}
}
}
if(dis[t]==-)return ;
return ;
}
int DFS(int s,int flow,int t){
if(s==t)return flow;
int ans=;
for(int i=head[s];i!=-;i=edge[i].next){
//cout<<34<<endl;
int v=edge[i].to;
if(edge[i].flow&&dis[v]==dis[s]+){
int f=DFS(v,min(flow-ans,edge[i].flow),t);
edge[i].flow-=f;
edge[i^].flow+=f;
ans+=f;
if(ans==flow)return ans;
}
}
return ans;
}
int Dinc(int s,int t){
int flow=;
while(BFS(s,t)){
// cout<<4<<endl;
flow=flow+DFS(s,INF,t);
}
return flow;
}
int main(){
int tt;
scanf("%d",&tt);
while(tt--){
int n;
double d;
int s,t;
scanf("%d%lf",&n,&d);
int sum=;
for(int i=;i<n;i++){
scanf("%lf%lf%d%d",&a[i].x,&a[i].y,&a[i].m,&a[i].k);
sum=sum+a[i].m;
}
s=*n+;
t=*n+;
int ss=;
for(int kk=;kk<n;kk++){
init();
add(kk,t,INF);
for(int i=;i<n;i++){
add(i,i+n,a[i].k);
add(s,i,a[i].m);
for(int j=i+;j<n;j++){
double dd=sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
if(dd<=d){
add(i+n,j,INF);
add(j+n,i,INF);
}
}
}
if(Dinc(s,t)==sum){
// cout<<kk<<endl;
b[ss++]=kk;
}
}
if(ss==)cout<<-<<endl;
else{
cout<<b[];
for(int i=;i<ss;i++)cout<<" "<<b[i];
cout<<endl;
}
}
}
poj 3498 March of the Penguins(拆点+枚举汇点 最大流)的更多相关文章
- [POJ 3498] March of the Penguins
March of the Penguins Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 4378 Accepted: ...
- poj 3498 March of the Penguins(最大流+拆点)
题目大意:在南极生活着一些企鹅,这些企鹅站在一些冰块上,现在要让这些企鹅都跳到同一个冰块上.但是企鹅有最大的跳跃距离,每只企鹅从冰块上跳走时会给冰块造成损害,因此企鹅跳离每个冰块都有次数限制.找出企鹅 ...
- POJ 3498 March of the Penguins(网络最大流)
Description Somewhere near the south pole, a number of penguins are standing on a number of ice floe ...
- poj 3498(最大流+拆点)
题目链接:http://poj.org/problem?id=3498 思路:首先设一个超级源点,将源点与各地相连,边容量为各点目前的企鹅数量,然后就是对每个冰块i进行拆点了(i,i+n),边容量为能 ...
- March of the Penguins
poj3498:http://poj.org/problem?id=3498 题意:某个冰块上有a只企鹅,总共可以跳出去b只,问是否可能所有的企鹅都跳到某一块冰块上,输出所有的可能的冰块的编号. 由于 ...
- poj 3498 最大流
March of the Penguins Time Limit: 8000MS Memory Limit: 65536K Total Submissions: 4809 Accepted: ...
- UVA 1658 海军上将(拆点法+最小费用限制流)
海军上将 紫书P375 这题我觉得有2个难点: 一是拆点,要有足够的想法才能把这题用网络流建模,并且知道如何拆点. 二是最小费用限制流,最小费用最大流我们都会,但如果限制流必须为一个值呢?比如这题限制 ...
- Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负
/** 题目:Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负 链接:https://vjudge.net/problem/UVA-1161 ...
- POJ 2391 Ombrophobic Bovines(二分+拆点+最大流)
http://poj.org/problem?id=2391 题意: 给定一个无向图,点i处有Ai头牛,点i处的牛棚能容纳Bi头牛,求一个最短时间T,使得在T时间内所有的牛都能进到某一牛棚里去. 思路 ...
随机推荐
- dotnetnuke 获得List 属性
new DotNetNuke.Common.Lists.ListController().GetListEntryInfo("DataType","Text") ...
- CNN结构:Windows使用FasterRCNN-C++版本
参考文章:Windows下VS2013 C++编译测试faster-rcnn. 本文与作者的所写方法有些许不同,欲速则不达,没有按照作者的推荐方法,绕了个弯弯. Windows版本纯C++版本的Fas ...
- js >> 右移操作符
十进制 十六进制 二进制 右移>> 十进制值 F 1F FF
- C# Winform 最大化后 任务栏还显示解决
//最大化 this.WindowState = FormWindowState.Maximized; //窗体最大化时 非全屏 不会遮盖任务栏 //去掉标题栏 this.FormBorderStyl ...
- PHP 之获取Windows下CPU、内存的使用率
<?php /** * Created by PhpStorm. * User: 25754 * Date: 2019/5/4 * Time: 13:42 */ class SystemInfo ...
- CAD调用导角命令,并返回导角的圆弧对象
主要用到函数说明: _DMxDrawX::SendStringToExecuteFun 把命令当着函数执行,可以传参数,详细说明如下: 参数 说明 IDispatch* pParam 命令参数,IMx ...
- Problem 42
Problem 42 https://projecteuler.net/problem=42 The nth term of the sequence of triangle numbers is g ...
- 使用 lua 编写 wireshark 协议解析插件
一.平台 操作系统:windows 7 wireshark:1.10.3 lua:5.1 二.准备 lua 语言基本语法,特别是关于表操作和循环 wireshark 文档,包括用户使用文档和开发者文档 ...
- jquery源码分析(三)——工具函数
jQuery.extend({ expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "&quo ...
- HDU 3208 Integer’s Power
Integer’s Power Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Origina ...