图论(差分约束系统):POJ 1275 Cashier Employment
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 7651 | Accepted: 2886 |
Description
The manager has provided you with the least number of cashiers
needed for every one-hour slot of the day. This data is given as R(0),
R(1), ..., R(23): R(0) represents the least number of cashiers needed
from midnight to 1:00 A.M., R(1) shows this number for duration of 1:00
A.M. to 2:00 A.M., and so on. Note that these numbers are the same every
day. There are N qualified applicants for this job. Each applicant i
works non-stop once each 24 hours in a shift of exactly 8 hours starting
from a specified hour, say ti (0 <= ti <= 23), exactly from the
start of the hour mentioned. That is, if the ith applicant is hired,
he/she will work starting from ti o'clock sharp for 8 hours. Cashiers
do not replace one another and work exactly as scheduled, and there are
enough cash registers and counters for those who are hired.
You are to write a program to read the R(i) 's for i=0..23 and ti
's for i=1..N that are all, non-negative integer numbers and compute the
least number of cashiers needed to be employed to meet the mentioned
constraints. Note that there can be more cashiers than the least number
needed for a specific slot.
Input
first line of input is the number of test cases for this problem (at
most 20). Each test case starts with 24 integer numbers representing the
R(0), R(1), ..., R(23) in one line (R(i) can be at most 1000). Then
there is N, number of applicants in another line (0 <= N <= 1000),
after which come N lines each containing one ti (0 <= ti <= 23).
There are no blank lines between test cases.
Output
If there is no solution for the test case, you should write No Solution for that case.
Sample Input
1
1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
5
0
23
22
1
10
Sample Output
1
#include <iostream>
#include <cstring>
#include <cstdio>
#define INF -1000000000
using namespace std;
int r[],t[];
int cnt,fir[],nxt[],to[],val[];
void addedge(int a,int b,int v)
{
nxt[++cnt]=fir[a];
fir[a]=cnt;to[cnt]=b;
val[cnt]=v;
}
int n,ans;
int dis[],in[],vis[],q[];
bool Spfa()
{
int S=,f=,b=;
for(int i=;i<=;i++)
dis[i]=INF;
memset(in,,sizeof(in));
memset(vis,,sizeof(vis)); q[b++]=S;
dis[S]=;
in[S]++;
vis[S]=;
while(f<b){
int node=q[f++];vis[node]=false;
for(int i=fir[node];i;i=nxt[i])
if(dis[to[i]]<dis[node]+val[i]){
dis[to[i]]=dis[node]+val[i];
if(!vis[to[i]]){
if(++in[to[i]]>n)
return false;
q[b++]=to[i];
vis[to[i]]=true;
}
}
}
return dis[]==ans;
} void Build()
{
memset(fir,,sizeof(fir));cnt=;
for(int i=;i<=;i++)
addedge(i-,i,r[i]); for(int i=;i<=;i++)
addedge(i+,i,r[i]-ans);
for(int i=;i<;i++){
addedge(i+,i,-t[i]);
addedge(i,i+,);
}
addedge(,,ans);
} void Solve()
{
int r=,h=n+;
while(h-r>)
{
ans=(r+h)>>;
Build();
if(Spfa())
h=ans;
else
r=ans;
}
if(h==n+)
printf("No Solution\n");
else
printf("%d\n",h);
} int main(){
int T;int x;
scanf("%d",&T);
while(T--)
{
for(int i=;i<=;i++)
scanf("%d",&r[i]);
scanf("%d",&n);
memset(t,,sizeof(t));
for(int i=;i<=n;i++){ scanf("%d",&x);
++t[x];
}
Solve();
}
return ;
}
图论(差分约束系统):POJ 1275 Cashier Employment的更多相关文章
- POJ 1275 Cashier Employment 挺难的差分约束题
http://poj.org/problem?id=1275 题目大意: 一商店二十四小时营业,但每个时间段需求的雇员数不同(已知,设为R[i]),现有n个人申请这份工作,其可以从固定时间t连续工作八 ...
- POJ 1275 Cashier Employment(差分约束)
http://poj.org/problem?id=1275 题意 : 一家24小时营业的超市,要雇出纳员,需要求出超市每天不同时段需要的出纳员数,午夜只需一小批,下午需要多些,希望雇最少的人,给出每 ...
- poj 1275 Cashier Employment - 差分约束 - 二分答案
A supermarket in Tehran is open 24 hours a day every day and needs a number of cashiers to fit its n ...
- poj 1275 Cashier Employment
http://poj.org/problem?id=1275 #include <cstdio> #include <cstring> #include <algorit ...
- 图论--差分约束--POJ 1364 King
Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen p ...
- POJ - Problem 1275 - Cashier Employment
· 对于差分约束,题目要求求什么便设什么,令$Sum[i]$表示由$0 ~ i$的雇佣人数. · 要充分利用题目所给条件,令$Have[i]$表示i时刻申报的人数,$Need[i]$表示i时刻需要的人 ...
- 图论(差分约束系统):POJ 1201 Intervals
Intervals Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 24099 Accepted: 9159 Descri ...
- 图论--差分约束--POJ 3159 Candies
Language:Default Candies Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 43021 Accep ...
- HDU [1529] || POJ [P1275] Cashier Employment
经典的差分约束+二分答案. 本题的难点在于如何建图. 设x[i] 表示第i个小时可以开始工作的有多少个人. num[i] 表示第i个小时最少需雇佣多少人. s[i] 表示1...i小时实际开始工作的有 ...
随机推荐
- 运行yum报错:Error: Cannot retrieve metalink for repository: epel. Please verify its path
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again 当我们安装第三方扩 ...
- 省市联级菜单--js+html
<!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...
- PHP错误类型及屏蔽方法
1. 注意(Notices)这些都是比较小而且不严重的错误,比如去访问一个未被定义的变量.通常,这类的错误是不提示给用户的,但有时这些错误会影响到运行的结果. 2. 警告(Warnings)这就是稍微 ...
- Codeforces 570D - Tree Requests【树形转线性,前缀和】
http://codeforces.com/contest/570/problem/D 给一棵有根树(50w个点)(指定根是1号节点),每个点上有一个小写字母,然后有最多50w个询问,每个询问给出x和 ...
- 第三篇:python基础之编码问题
python基础之编码问题 python基础之编码问题 本节内容 字符串编码问题由来 字符串编码解决方案 1.字符串编码问题由来 由于字符串编码是从ascii--->unicode---&g ...
- 网站出现 HTTP 错误 401.2 - 未经授权:访问由于服务器配置被拒绝
原因:关闭了匿名身份验证 解决方案: 在开始菜单中输入运行->inetmgr,打开站点属性->目录安全性->身份验证和访问控制->选中"启用匿名访问",输入 ...
- PageMapAdapter MapAdapter (续webServices)
public class PageMapAdapter extends XmlAdapter<PageMapConverter, IPage<Map<String, Object&g ...
- iOS sizeWithFont 过期 is deprecated
原文: http://www.cnblogs.com/A--G/p/4819189.html iOS 2.0之后 sizeWithFont就被弃用了: //计算textview 高度 - (float ...
- undefined与null的区别(待修整)
没有实体的对象称为空对象.只用对象的引用,而不存在引用的实体对象 就叫做空对象 在常见的强类型语言中,通常有一个表示"空"的值,比如NULL.但是在Javascript中,空(或者 ...
- 动态树LCT小结
最开始看动态树不知道找了多少资料,总感觉不能完全理解.但其实理解了就是那么一回事...动态树在某种意思上来说跟树链剖分很相似,都是为了解决序列问题,树链剖分由于树的形态是不变的,所以可以通过预处理节点 ...