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

题意:给你n个冰岛 有些岛上有企鹅  给定岛的坐标  已经岛上面的企鹅数  和当多少只企鹅离开岛会下沉
D表示企鹅能跳跃的距离
现在所有的企鹅要汇聚到一个岛上去 问你那些岛可以符合
题解:就是将一个岛进行拆点  拆成两个点 之间的容量就是最大运行多少企鹅走的数量
构图  求最大流是不是等于所有的企鹅数
因为100个点  所有我们可以选择枚举每个点 看看是否满足
 #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(拆点+枚举汇点 最大流)的更多相关文章

  1. [POJ 3498] March of the Penguins

    March of the Penguins Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 4378   Accepted:  ...

  2. poj 3498 March of the Penguins(最大流+拆点)

    题目大意:在南极生活着一些企鹅,这些企鹅站在一些冰块上,现在要让这些企鹅都跳到同一个冰块上.但是企鹅有最大的跳跃距离,每只企鹅从冰块上跳走时会给冰块造成损害,因此企鹅跳离每个冰块都有次数限制.找出企鹅 ...

  3. POJ 3498 March of the Penguins(网络最大流)

    Description Somewhere near the south pole, a number of penguins are standing on a number of ice floe ...

  4. poj 3498(最大流+拆点)

    题目链接:http://poj.org/problem?id=3498 思路:首先设一个超级源点,将源点与各地相连,边容量为各点目前的企鹅数量,然后就是对每个冰块i进行拆点了(i,i+n),边容量为能 ...

  5. March of the Penguins

    poj3498:http://poj.org/problem?id=3498 题意:某个冰块上有a只企鹅,总共可以跳出去b只,问是否可能所有的企鹅都跳到某一块冰块上,输出所有的可能的冰块的编号. 由于 ...

  6. poj 3498 最大流

    March of the Penguins Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 4809   Accepted:  ...

  7. UVA 1658 海军上将(拆点法+最小费用限制流)

    海军上将 紫书P375 这题我觉得有2个难点: 一是拆点,要有足够的想法才能把这题用网络流建模,并且知道如何拆点. 二是最小费用限制流,最小费用最大流我们都会,但如果限制流必须为一个值呢?比如这题限制 ...

  8. Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负

    /** 题目:Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负 链接:https://vjudge.net/problem/UVA-1161 ...

  9. POJ 2391 Ombrophobic Bovines(二分+拆点+最大流)

    http://poj.org/problem?id=2391 题意: 给定一个无向图,点i处有Ai头牛,点i处的牛棚能容纳Bi头牛,求一个最短时间T,使得在T时间内所有的牛都能进到某一牛棚里去. 思路 ...

随机推荐

  1. CSS——text-indent

    在h1标签里套入a标签并写上文字,有利于seo,但是文字如何隐藏呢?一般都是a标签变成内联块并首行缩进为负值. <!DOCTYPE html> <html lang="en ...

  2. SPA设计架构

    1.SPA是采用单页应用(Single Page Application)的方式来开发 2.SPA的框架有如Augular.js.Vue.js等.

  3. [Windows Server 2012] IIS自带FTP配置方法

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:IIS自带FT ...

  4. 如何描述bug

    清晰的标题 环境描述 已经采取了什么措施 结果 日志 Coredump 截图

  5. 微信 之jsapi实现支付

    一.微信公众号号后台支付配置 附微信支付参考文档:https://pay.weixin.qq.com/wiki/doc/api/index.html 二.微信支付类封装 该类可以实现付款码支付.JSA ...

  6. VUE路由history模式坑记--NGINX

    因微信分享和自动登录需要,对于URL中存在'#'的地址,处理起来比较坑(需要手动写一些代码来处理).还有可能会有一些隐藏的问题没被发现. 如果VUE能像其他(JSP/PHP)系统的路径一样,就不存在这 ...

  7. 安装部署NetBeans mysql Tomact joget workflow 环境

    一.安装joget workflow 1.安装jdk 下载jdk http://www.oracle.com/technetwork/java/javase/downloads/index.html ...

  8. collections、random、hashlib、configparser、logging模块

    collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdict. ...

  9. discourse论坛迁移

    在源设备的操作备份数据文件tar -czvf discoursefile716.tar.gz /var/discourse然后把此discoursefile716.tar.gz文件传到需要迁移的设备上 ...

  10. linux - redis基础

    目录 linux - redis基础 redis 源码编译安装 redis 数据结构 1. strings类型 2. list 类型 3. sets集合类型 有序集合 5. 哈希数据结构 centos ...