poj1275
Cashier Employment
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
题意 在一家超市里,每个时刻都需要有营业员看管,
R(i) (0 <= i < 24)表示从i时刻开始到i+1时刻需要的营业员的数目,
现在有N(N <= 1000)个申请人申请这项工作,并且每个申请者都有一个起始工作时间 ti,
如果第i个申请者被录用,那么他会从ti时刻开始连续工作8小时。现在要求选择一些申请者进行录用,
使得任何一个时刻i,营业员数目都能大于等于R(i)。求出至少需要录用多少营业员。
sol:超有趣的差分约束好题,令f[i]表示前i小时的人数总和,pp[i]表示那个小时的申请人数
则有一下约束
0<=f[i]-f[i-1]<=pp[i]
f[i]-f[i-8]>=r[i] 9<=i<=24
f[i]-f[16+i]+f[24]>=r[i] 1<=i<=8
然后因为有三个所以二分f[24]即答案
因为是最小值所以跑最长路
/*
题意 在一家超市里,每个时刻都需要有营业员看管,
R(i) (0 <= i < 24)表示从i时刻开始到i+1时刻需要的营业员的数目,
现在有N(N <= 1000)个申请人申请这项工作,并且每个申请者都有一个起始工作时间 ti,
如果第i个申请者被录用,那么他会从ti时刻开始连续工作8小时。现在要求选择一些申请者进行录用,
使得任何一个时刻i,营业员数目都能大于等于R(i)。求出至少需要录用多少营业员。
*/
#include <queue>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
//最小值最长路,最大值最短路
const int N=,M=,inf=0x3f3f3f3f;
int T,n,r[N],pp[N];
int tot=,Next[M],to[M],head[N],val[M];
bool Inq[N];
inline void init()
{
tot=; memset(head,,sizeof head);
}
inline void Link(int x,int y,int z)
{
Next[++tot]=head[x]; to[tot]=y; val[tot]=z; head[x]=tot;
}
int Dis[N],cnt[N];
inline bool spfa(int ans)
{
int i;
for(i=;i<=;i++) Dis[i]=-inf,cnt[i]=Inq[i]=;
queue<int>Que; while(!Que.empty()) Que.pop(); Que.push(); Dis[]=;
while(!Que.empty())
{
int x=Que.front(); Que.pop(); Inq[x]=;
// cout<<"x="<<x<<endl;
// system("pause");
for(i=head[x];i;i=Next[i])
{
if(Dis[to[i]]<Dis[x]+val[i])
{
Dis[to[i]]=Dis[x]+val[i];
if(!Inq[to[i]]) {Que.push(to[i]); Inq[to[i]]=;}
if((++cnt[to[i]])>) return false;
}
}
}
return (Dis[]==ans)?true:false;
}
int main()
{
freopen("poj1275.in","r",stdin);
int i;
R(T);
while(T--)
{
for(i=;i<=;i++) {pp[i]=; R(r[i]);}
R(n); for(i=;i<=n;i++) pp[read()+]++;
int ll=,rr=n+,ans=inf;
while(ll<=rr)
{
init();
int mid=(ll+rr)>>;
for(i=;i<=;i++) {Link(i-,i,); Link(i,i-,-pp[i]);}
for(i=;i<=;i++) Link(i-,i,r[i]);
for(i=;i<=;i++) Link(i+,i,r[i]-mid);
Link(,,mid);
if(spfa(mid)) ans=mid,rr=mid-;else ll=mid+;
// cout<<ll<<' '<<mid<<' '<<rr<<endl;
}
if(ans<=n) Wl(ans); else puts("No Solution");
}
return ;
}
/*
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
*/
poj1275的更多相关文章
- 【POJ1275】Cashier Employment
题目: Description A supermarket in Tehran is open 24 hours a day every day and needs a number of cashi ...
- [poj1275][Cashier Employment]
poj1275 题目大意: 每天有24小时,每个小时需要一定的人.有m个人每个人会有一个开始工作的时间,每个人会工作8小时,问至少需要多少人才能完成任务.如果这m个人也不能完成任务就输出"N ...
- POJ1275 Cashier Employment 【二分 + 差分约束】
题目链接 POJ1275 题解 显然可以差分约束 我们记\(W[i]\)为\(i\)时刻可以开始工作的人数 令\(s[i]\)为前\(i\)个时刻开始工作的人数的前缀和 每个时刻的要求\(r[i]\) ...
- 【POJ1275】Cashier Employment 差分约束
[POJ1275]Cashier Employment 题意: 超市经历已经提供一天里每一小时需要出纳员的最少数量————R(0),R(1),...,R(23).R(0)表示从午夜到凌晨1:00所需要 ...
- POJ1275 Cashier Employment[差分约束系统 || 单纯形法]
Cashier Employment Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7997 Accepted: 305 ...
- POJ1275/ZOJ1420/HDU1529 Cashier Employment (差分约束)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 题意:一商店二十四小时营业,但每个时间段需求的出纳员不同,现有n个人申请这份工作, ...
- POJ1275出纳员的雇佣【差分约束】
出纳员的雇佣 Tehran的一家每天24小时营业的超市,需要一批出纳员来满足它的需要.超市经理雇佣你来帮他解决问题:超市在每天的不同时段需要不同数目的出纳员(例如:午夜时只需一小批,而下午则需要很多) ...
- POJ1275 Cashier Employment(差分约束)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9078 Accepted: 3515 Description A sup ...
- POJ1275 Cashier Employment 二分、差分约束
传送门 题意太长 为了叙述方便,将题意中的$0$点看作$1$点,$23$点看做$24$点 考虑二分答案(其实从小到大枚举也是可以的) 设$x_i$是我们选的雇员第$i$小时开始工作的人数,$s_i$是 ...
随机推荐
- Python 语言简介与入门
Python 的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承.Py ...
- Java String类源码
String类的签名(JDK 8): public final class String implements java.io.Serializable, Comparable<String&g ...
- MyBatis 示例-主键回填
测试类:com.yjw.demo.PrimaryKeyTest 自增长列 数据库表的主键为自增长列,在写业务代码的时候,经常需要在表中新增一条数据后,能获得这条数据的主键 ID,MyBatis 提供了 ...
- 使用Visual Studio2019 开启Openmp的方法
调试-->属性-->C/C++-->所有选项-->Openmp支持改为 是(可以使用下拉菜单) 严重性 代码 说明 项目 文件 行 禁止显示状态 禁止显示状态 错误 C2338 ...
- hdu 1506 最大子矩阵面积
//写动态规划的题目 要把主要问题提炼出来 这里的问题就是求area=(j-k+1)*a[i] 如果找到j k是解决这个题目的关键 这里暴力求肯定是要超时的 这里用dp来优化 #include< ...
- TCP协议探究(二):超时与重试
1 概述 TCP提供可靠的运输层. 可靠性保证之一:确认从另一端收到的数据. 但数据和确认都有可能会丢失.TCP通过在发送时设置一个定时器来解决这种问题. 如果当定时器溢出时还没有收到确认,它就重传该 ...
- QT开发小技巧-窗口处理(一)
this->setWindowFlags(Qt::WindowCloseButtonHint); // 仅保留关闭按钮 this->setAttribute(Qt::WA_DeleteOn ...
- LeetCode 腾讯精选50题--合并K个排序链表
今天的题目稍微有点复杂了,因为是K个有序链表的合并,看到这道题后的大体思路是这样的: 1.首先先做到两个链表的合并,链表的合并我想到的是用递归操作, 2.其次是多个链表的合并,所以在第一步实现的基础上 ...
- JavaScript获取数组索引
JavaScript获取数组索引: <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...
- 处理器拦截器(HandlerInterceptor)详解(转)
简介 SpringWebMVC的处理器拦截器,类似于Servlet开发中的过滤器Filter,用于处理器进行预处理和后处理. 应用场景 1.日志记录,可以记录请求信息的日志,以便进行信息监控.信息统计 ...