POJ1275 Cashier Employment(差分约束)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 9078 | Accepted: 3515 |
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
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
Source
题意:
在一家超市里,每个时刻都需要有营业员看管,R(i) (0 <= i < 24)表示从i时刻开始到i+1时刻结束需要的营业员的数目,现在有N(N <= 1000)个申请人申请这项工作,并且每个申请者都有一个起始工作时间 ti,如果第i个申请者被录用,那么他会从ti时刻开始连续工作8小时。现在要求选择一些申请者进行录用,使得任何一个时刻i,营业员数目都能大于等于R(i)。求出至少需要录用多少营业员。
我们用$S[i]$表示一天内前$i+1$个小时录用的人员,
当$i>=7$时,我们需要满足$s[i]-s[i-8]>=R[i]$
当$0<=i<7$,经过推倒不难发现,我们需要满足$s[i]+s[23]-s[i+16]>=R[i]$
同时,因为题目中人数的限制,我们还需要满足$0<=s[i]-s[i-1]<=b[i]$
这样这道题就看起来可做了
但是我们的第二个式子左边有三项,不过还好$s[23]$是个常数项,我们可以二分解决
因为是求最小,所以我们按照套路连边,求最长路
#include<cstdio>
#include<queue>
#include<cstring>
#define INF 1e8+10
using namespace std;
const int MAXN=1e5+;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,MAXN,stdin),p1==p2)?EOF:*p1++)
char buf[MAXN],*p1=buf,*p2=buf;
inline int read()
{
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int R[MAXN],N,pep[MAXN],dis[MAXN],vis[MAXN];
struct node
{
int u,v,w,nxt;
}edge[MAXN];
int head[MAXN],num=;
inline void AddEdge(int x,int y,int z)
{
edge[num].u=x;
edge[num].v=y;
edge[num].w=z;
edge[num].nxt=head[x];
head[x]=num++;
}
void PRE()
{
memset(head,-,sizeof(head));
memset(vis,,sizeof(vis));
num=;
}
int SPFA(int val)
{
memset(dis,-0x7f,sizeof(dis));
queue<int>q;
dis[]=;
q.push();
while(q.size()!=)
{
int p=q.front();q.pop();
vis[p]=;
if(p==&&dis[p]>val) return ;
for(int i=head[p];i!=-;i=edge[i].nxt)
{
if(dis[edge[i].v]<dis[p]+edge[i].w)
{
dis[edge[i].v]=dis[p]+edge[i].w;
if(!vis[edge[i].v]) vis[edge[i].v]=,q.push(edge[i].v);
}
}
}
return dis[]<=val?:; }
int main()
{
#ifdef WIN32
freopen("a.in","r",stdin);
#else
#endif
int QWQ=read();
while(QWQ--)
{
memset(pep,,sizeof(pep));
for(int i=;i<=;i++) R[i]=read();
N=read();
for(int i=;i<=N;i++)
pep[read()]++;
int r=N+,l=;
int ans=INF;
while(l<=r)
{
PRE();
int mid=l+r>>;
for(int i=;i<=;i++) AddEdge(i,i+,),AddEdge(i+,i,-pep[i]);
for(int i=;i<=;i++) AddEdge(i-,i+,R[i]);
AddEdge(,,mid);AddEdge(,,-mid);
for(int i=;i<;i++) AddEdge(i+,i+,R[i]-mid);
if(SPFA(mid)) ans=mid,r=mid-;
else l=mid+;
}
if(ans>N) printf("No Solution\n");
else printf("%d\n",ans);
}
return ;
}
POJ1275 Cashier Employment(差分约束)的更多相关文章
- 【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个人申请这份工作, ...
- POJ1275 Cashier Employment[差分约束系统 || 单纯形法]
Cashier Employment Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7997 Accepted: 305 ...
- hdu1529 Cashier Employment[差分约束+二分答案]
这题是一个类似于区间选点,但是有一些不等式有三个未知量参与的情况. 依题意,套路性的,将小时数向右平移1个单位后,设$f_i$为前$i$小时工作的人数最少是多少,$f_{24}$即为所求.设$c_i$ ...
- HDU.1529.Cashier Employment(差分约束 最长路SPFA)
题目链接 \(Description\) 给定一天24h 每小时需要的员工数量Ri,有n个员工,已知每个员工开始工作的时间ti(ti∈[0,23]),每个员工会连续工作8h. 问能否满足一天的需求.若 ...
- Cashier Employment 差分约束
题意:有一个超市需要一些出纳员,已给出这个超市在各个时间段(0-1,1-2,2-3...共24个时间段)至少需要的出纳员数目,现在前来应聘有n个人,每个人都有一个固定的开始工作的时间,这也意味着从这个 ...
- 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 ...
- [HDU 1529]Cashier Employment(差分约束系统)
[HDU 1529]Cashier Employment(差分约束系统) 题面 有一个超市,在24小时对员工都有一定需求量,表示为\(r_i\),意思为在i这个时间至少要有i个员工,现在有n个员工来应 ...
- POJ1275 Cashier Employment 【二分 + 差分约束】
题目链接 POJ1275 题解 显然可以差分约束 我们记\(W[i]\)为\(i\)时刻可以开始工作的人数 令\(s[i]\)为前\(i\)个时刻开始工作的人数的前缀和 每个时刻的要求\(r[i]\) ...
随机推荐
- jsp进阶
Jsp,前段的数据读取到后端 获取前段输入框数据 request.getParameter(前段输入框的name值) Request.代表转发,(代码在服务器内部执行的一次性请求,url地址不会发生改 ...
- Python - 一些值得阅读的PEP
1- PEP简介 PEP是Python增强提案(Python Enhancement Proposal)的缩写.社区通过PEP来给Python语言建言献策,每个版本的新特性和变化都是通过PEP提案经过 ...
- 超声波手势识别(STM32四路超声波获取)
超声波手势识别在市场上已经有见实现,但研究其传感器发现并不是市场上随意可见的,如果暂且考虑成本,该如何入门实现简单的手势识别呢.聊天中老师给出一个很好的提议,就是固定四个超声波,分别为上下左右,然后进 ...
- Mac OS Eclipse 调试快捷键不好使(失效)的情况
Eclipse调试使用的F5 F6 F8一直都好用,结果一次调试后忽然不好使. 问题原因,尚未知晓. 解决办法,重启机器.
- 十大经典排序算法(python实现)(原创)
个人最喜欢的排序方法是非比较类的计数排序,简单粗暴.专治花里胡哨!!! 使用场景: 1,空间复杂度 越低越好.n值较大: 堆排序 O(nlog2n) O(1) 2,无空间复杂度要求.n值较大: 桶排序 ...
- 关于vue2.0+hbuilder打包移动端app之后空白页面的解决方案
楼主是使用vue-cli构建的页面,代码是vscode,然后使用hbuilder打包成移动端的安装包.首先确认在npm run build 之后没有问题(默认dist文件夹),可以使用anywhere ...
- Elastic Job学习
从执行的结果来看,随着服务器的增加,分片的结果也不一样 当只有一台服务器的时候,所有分片都到这一台服务器上 当服务器增加到两台的时候,分片的结果是0 1 2 3 4和5 6 7 8 9 当服务器增加到 ...
- 《JavaScript总结》js的运行机制
首先大家都知道javascript是单线程语言. 什么是单线程呢?比如我们去车站买票,只有一个售票窗口,大家排队买票,需要前面的人买完票,后面的人才能买票. 那为什么javascript不能是多线程呢 ...
- PowerDesigner使用方法
我们需要创建一个测试数据库,一步一步来学习使用PowerDesigner,为了简单,我们在这个数据库中只创建一个Student表和一个Major表.其表结构和关系如下所示. 看看怎样用PowerDes ...
- HTTP的基本原理
用户访问万维网文档,万维网文档之间的链接以及万维网文档中数据传送到用户计算机,这些功能的实现都是由超文本传输协议 HTTP(HyperTextTransfer Protocol) 负责完成的. HTT ...