hdu 1529 Cashier Employment(差分约束)
Cashier Employment
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1214 Accepted Submission(s): 537
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.
If there is no solution for the test case, you should write No Solution for that case.
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
较为难的差分约束系统。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#define INF 1000000000
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define clrmax(x) memset(x,0x3f3f3f3f,sizeof(x))
#define clrmin(x) memset(x,-0x3f3f3f3f,sizeof(x))
using namespace std;
struct node
{
int to,val,next;
}edge[*];
queue<int> Q;
int head[];
int dis[];
int R[];
int in[],inf[];
int x[];
int c[];
int n,cnt,l,r,k,ans;
void addedge(int l,int r,int k);
bool spfa(int s);
void init();
int min(int a,int b)
{
return a<b?a:b;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
clr(x);
while(!Q.empty())
Q.pop();
for(int i=;i<=;i++)
scanf("%d",&R[i]);
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&l);
x[l]++;
}
c[]=;
for(int i=;i<=;i++)
{
c[i]=c[i-]+x[i-];
}
ans=-;
for(int kase=;kase<=n;kase++)
{
init();
for(int i=;i<=;i++)
addedge(+i,i,R[i-]-kase);
for(int i=;i<=;i++)
addedge(i-,i,R[i-]);
for(int i=;i<=;i++)
{
addedge(i,i-,-x[i-]);
addedge(i-,i,);
}
addedge(,,kase);
if(spfa())
{
ans=kase;
break;
}
}
if(ans==-)
printf("No Solution\n");
else
printf("%d\n",ans);
}
return ;
}
void addedge(int l,int r,int k)
{
edge[++cnt].to=r;
edge[cnt].val=k;
edge[cnt].next=head[l];
head[l]=cnt;
return;
}
bool spfa(int s)
{
dis[s]=;
Q.push(s);
inf[s]=;
in[s]=;
int v,k;
while(!Q.empty())
{
v=Q.front();
Q.pop();
inf[v]=;
k=head[v];
while(k!=-)
{
if(dis[v]+edge[k].val>dis[edge[k].to])
{
dis[edge[k].to]=dis[v]+edge[k].val;
if(!inf[edge[k].to])
{
if(++in[edge[k].to]>)
return false;
inf[edge[k].to]=;
Q.push(edge[k].to);
}
}
k=edge[k].next;
}
}
return true;
}
void init()
{
clr(inf);
clr_1(head);
clrmin(dis);
clr(in);
cnt=;
return ;
}
hdu 1529 Cashier Employment(差分约束)的更多相关文章
- HDU.1529.Cashier Employment(差分约束 最长路SPFA)
题目链接 \(Description\) 给定一天24h 每小时需要的员工数量Ri,有n个员工,已知每个员工开始工作的时间ti(ti∈[0,23]),每个员工会连续工作8h. 问能否满足一天的需求.若 ...
- [HDU 1529]Cashier Employment(差分约束系统)
[HDU 1529]Cashier Employment(差分约束系统) 题面 有一个超市,在24小时对员工都有一定需求量,表示为\(r_i\),意思为在i这个时间至少要有i个员工,现在有n个员工来应 ...
- 【POJ1275】Cashier Employment 差分约束
[POJ1275]Cashier Employment 题意: 超市经历已经提供一天里每一小时需要出纳员的最少数量————R(0),R(1),...,R(23).R(0)表示从午夜到凌晨1:00所需要 ...
- POJ1275/ZOJ1420/HDU1529 Cashier Employment (差分约束)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 题意:一商店二十四小时营业,但每个时间段需求的出纳员不同,现有n个人申请这份工作, ...
- hdu1529 Cashier Employment[差分约束+二分答案]
这题是一个类似于区间选点,但是有一些不等式有三个未知量参与的情况. 依题意,套路性的,将小时数向右平移1个单位后,设$f_i$为前$i$小时工作的人数最少是多少,$f_{24}$即为所求.设$c_i$ ...
- Cashier Employment 差分约束
题意:有一个超市需要一些出纳员,已给出这个超市在各个时间段(0-1,1-2,2-3...共24个时间段)至少需要的出纳员数目,现在前来应聘有n个人,每个人都有一个固定的开始工作的时间,这也意味着从这个 ...
- POJ1275 Cashier Employment(差分约束)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9078 Accepted: 3515 Description A sup ...
- 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 ...
- POJ1275 Cashier Employment[差分约束系统 || 单纯形法]
Cashier Employment Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7997 Accepted: 305 ...
随机推荐
- POJ 3276 Face The Right Way (尺取法)
题目链接 Description Farmer John has arranged his N (1 ≤ N ≤ 5,000) cows in a row and many of them are f ...
- 安装Vue.js devtools
1.下载安装 https://github.com/vuejs/vue-devtools#vue-devtools 通过以上地址下载安装包,解压以后进入文件,按住shift,点击鼠标右键打开命令窗口 ...
- 【设计模式】迭代器模式(Iterator )
摘要: 1.本文将详细介绍迭代器模式的原理和实际代码中特别是Android系统代码中的应用. 纲要: 1. 引入迭代器模式 2. 迭代器的概念及优缺点介绍 3. 迭代器在Android源码中的应用 1 ...
- MinnowBoard
MinnowBoard https://github.com/RafaelRMachado/MinnowBoard https://github.com/RafaelRMachado https:// ...
- Android 开发之避免被第三方使用代理抓包
现象:charles抓不到包,但wireshark,HttpAnalyzor可以抓到包. 关键代码: URL url = new URL(urlStr); urlConnection = (HttpU ...
- sicily 1046. Plane Spotting
1046. Plane Spotting Time Limit: 1sec Memory Limit:32MB Description Craig is fond of planes. Mak ...
- Oracle with重用子查询
--with 重用子查询对于多次使用相同子查询的复杂查询语句来说,用户可能会将查询语句分成两条语句执行.第一条语句将子查询结果存放到临时表,第二条查询语句使用临时表处理数据.从 Oracle 9i 开 ...
- C json实战引擎 三 , 最后实现部分辅助函数
引言 大学读的是一个很时髦的专业, 学了四年的游戏竞技. 可惜没学好. 但认真过, 比做什么都认真. 见证了 ...... 打的所有游戏人物中 分享一位最喜爱 的 “I've been alone ...
- HDU 4768: Flyer
题意: 有N个社团,每个社团三个属性A,B,C,表示会向编号A+k*C的同学发传单(k=0,1,2... && A+k*C <= B).题目保证最多有一个人收到的传单数是奇数. ...
- mysql 服务器配置
Windows: 1.在bin目录下执行mysqld.exe --install-manual安装服务(删除命令是mysqld.exe --remove) 2.执行net start mysql启动服 ...