博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
URAL 1774 A - Barber of the Army of Mages 最大流
阅读量:6292 次
发布时间:2019-06-22

本文共 4815 字,大约阅读时间需要 16 分钟。

A - Barber of the Army of Mages

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87643#problem/A

Description

Petr, elected as a warlord of the army of mages, faced a challenging problem. All magicians recruited in the army had heavy beards, which were quite unacceptable for soldiers. Therefore, Petr ordered all recruits to shave their beards as soon as possible. Of course, all magicians refused to do it, referring to the fact they don't know any shaving spell. Fortunately, a magician Barberian agreed to shave all recruits.
Barberian can cast a “Fusion Power” spell which shaves beards of at most 
k magicians in one minute. In order to achieve full effect every magician should be shaved twice: the first spell shaves close, the second spell shaves even closer. For each recruit Petr appointed a time when he should visit Barberian. Unfortunately, the discipline in the new army is still far from perfect, so every magician will come to Barberian in time, but everyone will wait for the shave until his patience is exhausted and will disappear after that.
Determine whether Barberian will be able to shave beards of all magicians before they disappear.

Input

The first line contains two space-separated integers n and k (1 ≤ nk ≤ 100) , which are the number of recruits in the army and the number of magicians Barber can shave simultaneously. The i-th of the following n lines contains space-separated integers ti and si(0 ≤ ti ≤ 1000; 2 ≤ si ≤ 1000) , which are the time in minutes, at which the i-th magician must come to Barberian, and the time in minutes he is ready to spend there, including shaving time.

Output

If Barberian is able to shave beards of all magicians, output “Yes” in the first line. The i-th of the following n lines should contain a pair of integers piqi, which are the moments at which Barberian should cast the spell on the i-th magician ( ti ≤ pi < qi ≤ ti + si − 1) . If at least one magician disappears before being completely shaved, output a single word “No”.

Sample Input

3 2

1 3
1 3
1 3

Sample Output

Yes

1 2
1 3
2 3

HINT

 

题意

有n个顾客,每个顾客需要理2次胡须

每一秒,理发师可以给k个人理发

然后每个顾客必须在x秒到x+y-1秒内理完

然后让你构造出一种解

题解

网络流,贪心的话就走远了……

S-2-顾客-1-天数-k-T

然后跑一发最大流就好了

代码:

//qscqesze#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef long long ll;using namespace std;//freopen("D.in","r",stdin);//freopen("D.out","w",stdout);#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)#define maxn 5000#define mod 10007#define eps 1e-9int Num;//const int inf=0x7fffffff; //нчоч╢Сconst int inf=0x3f3f3f3f;inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}//**************************************************************************************namespace NetFlow{ const int MAXN=100000,MAXM=500000,inf=1e9; vector
Q[1100]; struct Edge { int v,c,f,nx; Edge() {} Edge(int v,int c,int f,int nx):v(v),c(c),f(f),nx(nx) {} } E[MAXM]; int G[MAXN],cur[MAXN],pre[MAXN],dis[MAXN],gap[MAXN],N,sz; void init(int _n) { N=_n,sz=0; memset(G,-1,sizeof(G[0])*N); } void link(int u,int v,int c) { E[sz]=Edge(v,c,0,G[u]); G[u]=sz++; E[sz]=Edge(u,0,0,G[v]); G[v]=sz++; } int ISAP(int S,int T) { //S -> T int maxflow=0,aug=inf,flag=false,u,v; for (int i=0;i
E[it].f&&dis[u]==dis[v=E[it].v]+1) { if (aug>E[it].c-E[it].f) aug=E[it].c-E[it].f; pre[v]=u,u=v; flag=true; if (u==T) { for (maxflow+=aug;u!=S;) { E[cur[u=pre[u]]].f+=aug; E[cur[u]^1].f-=aug; } aug=inf; } break; } } if (flag) continue; int mx=N; for (int it=G[u];~it;it=E[it].nx) { if (E[it].c>E[it].f&&dis[E[it].v]
E[it].f) { dis[v]=dis[u]+1; Q[t++]=v; } } } return dis[T]!=-1; } int dfs(int u,int T,int low) { if (u==T) return low; int ret=0,tmp,v; for (int &it=cur[u];~it&&ret
E[it].f) { if (tmp=dfs(v,T,min(low-ret,E[it].c-E[it].f))) { ret+=tmp; E[it].f+=tmp; E[it^1].f-=tmp; } } } if (!ret) dis[u]=-1; return ret; } int dinic(int S,int T) { int maxflow=0,tmp; while (bfs(S,T)) { memcpy(cur,G,sizeof(G[0])*N); while (tmp=dfs(S,T,inf)) maxflow+=tmp; } return maxflow; } void solve(int S,int T,int p,int n) { int C = dinic(S,T); if(C!=p) printf("No\n"); else { printf("Yes\n"); for(int i=1;i<=n;i++) { int flag=0; for(int j=G[i+10];j!=-1;j=E[j].nx) { if(E[j].f==1) { Q[i].push_back(E[j].v-150); } } printf("%d %d\n",Q[i][1],Q[i][0]); } } }}using namespace NetFlow;int vis[5200];int main(){ init(5000); int n=read(),k=read(); for(int i=11;i<=10+n;i++) link(1,i,2); for(int i=1;i<=n;i++) { int x=read(),y=read(); for(int j=x;j<=x+y-1;j++) { link(i+10,150+j,1); if(!vis[j]) { vis[j]=1; link(150+j,3000,k); } } } solve(1,3000,2*n,n); //cout<
<

 

转载地址:http://idcta.baihongyu.com/

你可能感兴趣的文章
Python 数据类型
查看>>
iOS--环信集成并修改头像和昵称(需要自己的服务器)
查看>>
PHP版微信权限验证配置,音频文件下载,FFmpeg转码,上传OSS和删除转存服务器本地文件...
查看>>
教程前言 - 回归宣言
查看>>
PHP 7.1是否支持操作符重载?
查看>>
Vue.js 中v-for和v-if一起使用,来判断select中的option为选中项
查看>>
Java中AES加密解密以及签名校验
查看>>
定义内部类 继承 AsyncTask 来实现异步网络请求
查看>>
VC中怎么读取.txt文件
查看>>
如何清理mac系统垃圾
查看>>
企业中最佳虚拟机软件应用程序—Parallels Deskto
查看>>
Nginx配置文件详细说明
查看>>
怎么用Navicat Premium图标编辑器创建表
查看>>
Spring配置文件(2)配置方式
查看>>
MariaDB/Mysql 批量插入 批量更新
查看>>
ItelliJ IDEA开发工具使用—创建一个web项目
查看>>
solr-4.10.4部署到tomcat6
查看>>
切片键(Shard Keys)
查看>>
淘宝API-类目
查看>>
virtualbox 笔记
查看>>