Cashier Employment
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7651   Accepted: 2886

Description

A supermarket in Tehran is open 24 hours a day every day and needs a number of cashiers to fit its need. The supermarket manager has hired you to help him, solve his problem. The problem is that the supermarket needs different number of cashiers at different times of each day (for example, a few cashiers after midnight, and many in the afternoon) to provide good service to its customers, and he wants to hire the least number of cashiers for this job.

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

The
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

For each test case, the output should be written in one line, which is the least number of cashiers needed.

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的更多相关文章

  1. POJ 1275 Cashier Employment 挺难的差分约束题

    http://poj.org/problem?id=1275 题目大意: 一商店二十四小时营业,但每个时间段需求的雇员数不同(已知,设为R[i]),现有n个人申请这份工作,其可以从固定时间t连续工作八 ...

  2. POJ 1275 Cashier Employment(差分约束)

    http://poj.org/problem?id=1275 题意 : 一家24小时营业的超市,要雇出纳员,需要求出超市每天不同时段需要的出纳员数,午夜只需一小批,下午需要多些,希望雇最少的人,给出每 ...

  3. 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 ...

  4. poj 1275 Cashier Employment

    http://poj.org/problem?id=1275 #include <cstdio> #include <cstring> #include <algorit ...

  5. 图论--差分约束--POJ 1364 King

    Description Once, in one kingdom, there was a queen and that queen was expecting a baby. The queen p ...

  6. POJ - Problem 1275 - Cashier Employment

    · 对于差分约束,题目要求求什么便设什么,令$Sum[i]$表示由$0 ~ i$的雇佣人数. · 要充分利用题目所给条件,令$Have[i]$表示i时刻申报的人数,$Need[i]$表示i时刻需要的人 ...

  7. 图论(差分约束系统):POJ 1201 Intervals

    Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24099   Accepted: 9159 Descri ...

  8. 图论--差分约束--POJ 3159 Candies

    Language:Default Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 43021   Accep ...

  9. HDU [1529] || POJ [P1275] Cashier Employment

    经典的差分约束+二分答案. 本题的难点在于如何建图. 设x[i] 表示第i个小时可以开始工作的有多少个人. num[i] 表示第i个小时最少需雇佣多少人. s[i] 表示1...i小时实际开始工作的有 ...

随机推荐

  1. Linux软件安装,RPM与YUM

    为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/3843955.html ...

  2. node基础再现--module.exports 和exports

    实际上,最最基础的方法,最最原始的方法是module.exports,至于exports,是为了方便书写才出来的,应该说,module.exports 包含exports,所工作的范围更加的广泛! m ...

  3. maven项目下tomcat直接启动不了(LifecycleException)。报错如下截图

    经查,tomcat项目下的lib中没有jar包,发布的时候没有将jar包发布上去.这个问题在我的博客中以前遇到过.如何将maven的jar发布到项目中,我的博客里面有记载

  4. 关于 ASP.NET 验证码

    Session["CheckCode"] 这个..不懂神马意思.. .创建一个用户控件 用户名:TextBox 密码: TextBox 验证码:TextBox 验证码图片 < ...

  5. WebSocket基于javaweb+tomcat的简易demo程序

    由于项目需要,前端向后台发起请求后,后台需要分成多个步骤进行相关操作,而且不能确定各步骤完成所需要的时间 倘若使用ajax重复访问后台以获取实时数据,显然不合适,无论是对客户端,还是服务端的资源很是浪 ...

  6. Java反射与代理

    Java反射机制与动态代理,使得Java更加强大,Spring核心概念IoC.AOP就是通过反射机制与动态代理实现的. 1       Java反射 示例: User user = new User( ...

  7. Linux中的find指令

    find find是最常见和最强大的查找命令,在磁盘中查找文件,用它找到任何你想找的文件,就是速度有点慢. find    path    -option    [    -print ]    [ ...

  8. 【POJ2352】【树状数组】Stars

    Description Astronomers often examine star maps where stars are represented by points on a plane and ...

  9. topcoder算法练习3

    SRM144 DIV1 1100 point Problem Statement      NOTE: There are images in the examples section of this ...

  10. phpcms(4) V9 栏目管理

    phpcms V9框架系统后台管理之栏目管理,请参见下文的源码分析(添加栏目和修改栏目): 参照添加栏目的界面图示,便于对源代码的理解: <?php   // 文件路径:phpcms/modul ...