图论(差分约束系统):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小时实际开始工作的有 ...
随机推荐
- 利用jpedal进行pdf转换成jpeg,jpg,png,tiff,tif等格式的图片
项目中运用到pdf文件转换成image图片,开始时使用pdfbox开源库进行图片转换,但是转换出来的文件中含有部分乱码的情况.下面是pdfBox 的pdf转换图片的代码示例. try{ String ...
- sql语句游标的写法
当循环查找一张表的信息时,我们得写一张游标来对每条信息进行操作,具体格式如下 DECLARE @fitemid int DECLARE #point_cursor CURSORFORSELECT fi ...
- ASP.NET Boilerplate Castle容器无缝添加日志功能
以添加log4net日志框架为例进行讲解 1.通常log4net的配置参数放在单独的配置文件中,但也可以写在web.config中,这里在我们的web项目中添加log4net.config应用配置文件 ...
- jdbc - Insert 'Date' value in PreparedStatement
“preparedStatement.setDate()”方法接受的是 'java.sql.Date' 类型的参数,而我们一般格式化日期所使用的是'java.util.Date'中的'SimpleDa ...
- ToString格式.
C 货币 2.5.ToString("C") ¥2.50 D 十进制数 25.ToString("D5") 00025 E 科学型 25000.ToString ...
- iOS 集成支付宝遇到的问题(续)
调起支付宝进行支付时提示private key is null ,碰到这个问题有两种解决方案 第一种. 将私钥转成PKCS8替换一下原私钥即可 1.生成私钥pem, 执行命令openssl genr ...
- spring-quartz普通任务与可传参任务
两者区别与作用: 普通任务:总调度(SchedulerFactoryBean)--> 定时调度器(CronTriggerFactoryBean) --> 调度明细自定义执行方法bean(M ...
- corejava_chap02
//单行注释 --不能用在一行代码的中间/**/多行注释 --任何地方/** */文档注释 文档注释用在:package.class.member variables.member method. ...
- 用css3实现鼠标移进去当前亮其他变灰
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- Html5新增加的属性
用2中方法给单复选框增加新的特性,使直接点击文字就可以被选中 1.将选项放入label标签内添加for属性,并在input标签内添加id,两者值相同. 2.将input标签放到label标签内,注意l ...