Cashier Employment
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7997   Accepted: 3054

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

Source


 德黑兰的一家每天24小时营业的超市,需要一批出纳员来满足它的需求。超市经理雇佣你来帮他解决一个问题————超市在每天的不同时段需要不同数目的出纳员(例如,午夜只需一小批,而下午则需要很多)来为顾客提供优质服务,他希望雇佣最少数目的纳员。
超市经历已经提供一天里每一小时需要出纳员的最少数量————R(),R(),...,R()。R()表示从午夜到凌晨1:00所需要出纳员的最少数目;R()表示凌晨1:00到2:00之间需要的;等等。每一天,这些数据都是相同的。有N人申请这项工作,每个申请者i在每天24小时当中,从一个特定的时刻开始连续工作恰好8小时。定义ti(<=ti<=)为上面提到的开始时刻,也就是说,如果第i个申请者被录用,他(或她)将从ti时刻开始连续工作8小时。
试着编写一个程序,输入R(i),i=,...,,以及ti,i=,...,N,它们都是非负整数,计算为满足上述限制需要雇佣的最少出纳员数目、在每一时刻可以有比对应R(i)更多的出纳员在工作
输入描述:
输入文件的第1行为一个整数T,表示输入文件中测试数据的数目(至多20个)。每个测试数据第一行为24个整数,表示R(),R(),...,R(),R(i)最大可以取到1000。接下来一行是一个整数N,表示申请者的数目,<=N<=。接下来有N行,每行为一个整数ti,<=ti<=,测试数据之间没有空行。
输出描述:
对输入文件中的每个测试数据,输出占一行,为需要雇佣的出纳员的最少数目。如果某个测试数据没有解。则输出"No Solution"。

题意


看到后第一反应:这不是noi2008志愿者吗,只不过没有了每个人的花费,最小化人数,花费设为1

一个时间段一个约束 24个,一个人一个变量 1000个,x为每个人选不选,A[i][j]=1当tj<=i<tj+8(注意时间循环)

最小化 x

满足约束 Ax<R

然后有很多细节问题:

1.我靠多组数据,初始化a[][] v

2.我靠连续8小时可以循环,24之后是1,改(我的是从1到24)

3.我靠还有无解的情况,判断选所有人可不可行

4.我靠无解用的sum数组也要清空

然后终于AC了,16ms(一片0ms),然而思维难度大大降低

一点总结:这种样子的题目都碰到3个了.......

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=,M=;
const double eps=1e-,INF=1e9;
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 n=,m,t;
double a[M][N],b[M],c[N],v;int sum[N];
void init(){
memset(a,,sizeof(a));
memset(sum,,sizeof(sum));
v=0.0;
}
void pivot(int l,int e){
b[l]/=a[l][e];
for(int j=;j<=n;j++) if(j!=e) a[l][j]/=a[l][e];
a[l][e]=/a[l][e];
for(int i=;i<=m;i++) if(i!=l&&fabs(a[i][e])>){
b[i]-=a[i][e]*b[l];
for(int j=;j<=n;j++) if(j!=e) a[i][j]-=a[i][e]*a[l][j];
a[i][e]=-a[i][e]*a[l][e];
}
v+=c[e]*b[l];
for(int j=;j<=n;j++) if(j!=e) c[j]-=c[e]*a[l][j];
c[e]=-c[e]*a[l][e];
}
double simplex(){
while(true){
int e=,l=;
for(e=;e<=n;e++) if(c[e]>eps) break;
if(e==n+) return v;
double mn=INF;
for(int i=;i<=m;i++)
if(a[i][e]>eps&&mn>b[i]/a[i][e]) mn=b[i]/a[i][e],l=i;
if(mn==INF) return INF;//unbounded
pivot(l,e);
}
} bool check(){
for(int i=;i<=n;i++) if(sum[i]<c[i]) return ;
return ;
}
int main(){
//freopen("in.txt","r",stdin);
int T=read();
while(T--){
init();
for(int i=;i<=n;i++) c[i]=read();
m=read();
for(int i=;i<=m;i++){
t=read()+;
for(int j=;j<=;j++){
if(t==) t=;//printf("hi %d\n",t);
a[i][t]=; sum[t]++;
t++;
}
b[i]=;
}
if(!check()){puts("No Solution");continue;}
simplex();
printf("%d\n",(int)(v+0.5));
}
}
 

POJ1275 Cashier Employment[差分约束系统 || 单纯形法]的更多相关文章

  1. [HDU 1529]Cashier Employment(差分约束系统)

    [HDU 1529]Cashier Employment(差分约束系统) 题面 有一个超市,在24小时对员工都有一定需求量,表示为\(r_i\),意思为在i这个时间至少要有i个员工,现在有n个员工来应 ...

  2. POJ1275 Cashier Employment(差分约束)

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9078   Accepted: 3515 Description A sup ...

  3. 【POJ1275】Cashier Employment 差分约束

    [POJ1275]Cashier Employment 题意: 超市经历已经提供一天里每一小时需要出纳员的最少数量————R(0),R(1),...,R(23).R(0)表示从午夜到凌晨1:00所需要 ...

  4. POJ1275 Cashier Employment 【二分 + 差分约束】

    题目链接 POJ1275 题解 显然可以差分约束 我们记\(W[i]\)为\(i\)时刻可以开始工作的人数 令\(s[i]\)为前\(i\)个时刻开始工作的人数的前缀和 每个时刻的要求\(r[i]\) ...

  5. POJ1275/ZOJ1420/HDU1529 Cashier Employment (差分约束)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 题意:一商店二十四小时营业,但每个时间段需求的出纳员不同,现有n个人申请这份工作, ...

  6. POJ1275 Cashier Employment 二分、差分约束

    传送门 题意太长 为了叙述方便,将题意中的$0$点看作$1$点,$23$点看做$24$点 考虑二分答案(其实从小到大枚举也是可以的) 设$x_i$是我们选的雇员第$i$小时开始工作的人数,$s_i$是 ...

  7. [poj1275][Cashier Employment]

    poj1275 题目大意: 每天有24小时,每个小时需要一定的人.有m个人每个人会有一个开始工作的时间,每个人会工作8小时,问至少需要多少人才能完成任务.如果这m个人也不能完成任务就输出"N ...

  8. HDU.1529.Cashier Employment(差分约束 最长路SPFA)

    题目链接 \(Description\) 给定一天24h 每小时需要的员工数量Ri,有n个员工,已知每个员工开始工作的时间ti(ti∈[0,23]),每个员工会连续工作8h. 问能否满足一天的需求.若 ...

  9. hdu1529 Cashier Employment[差分约束+二分答案]

    这题是一个类似于区间选点,但是有一些不等式有三个未知量参与的情况. 依题意,套路性的,将小时数向右平移1个单位后,设$f_i$为前$i$小时工作的人数最少是多少,$f_{24}$即为所求.设$c_i$ ...

随机推荐

  1. 单例模式 - Singleton

    对今天学习的Singleton Pattern简单总结下: 定义:保证一个类只有一个实例,必须自己创建自己的实例,并提供一个访问它的全局访问点. private 构造函数: private stati ...

  2. 基于CkEditor实现.net在线开发之路(3)常用From表单控件介绍与说明

    上一章已经简单介绍了CKEditor控件可以编写C#代码,然后可以通过ajax去调用,但是要在网页上面编写所有C#后台逻辑,肯定痛苦死了,不说实现复杂的逻辑,就算实现一个简单增删改查,都会让人头痛欲裂 ...

  3. jquery 文本/html/值

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. Jar mismatch错误的解决

    新建了一个项目,包含了两个库:appcompat_v7和swipelistview,结果出现了Jar mismatch错误: [2016-04-11 17:17:27 - MySwipeListVie ...

  5. JQuery 快速入门

    1.要学习Jquery @首先要在需要的页面引入 <script type="text/javascript" src="jquery.js">&l ...

  6. IOS 2D游戏开发框架 SpriteKit-->续(完善角色功能)

    一.说明       今天给角色精灵增加了子弹发射功能,增加了子弹与敌对精灵的碰撞检测,当角色精灵子弹与敌对精灵碰撞后,它们都会从屏幕上消失. 二.场景层SKScene的修改 1. 在初始化场景层的方 ...

  7. 转载:《TypeScript 中文入门教程》 2、枚举

    版权 文章转载自:https://github.com/zhongsp 建议您直接跳转到上面的网址查看最新版本. 由于第一章节是我翻译的,而且与他的版本不一致,导致第一章节有枚举这部分,而他的第二章节 ...

  8. Java-使用二叉树实现快速排序-遁地龙卷风

    (-1)写在前面 在一次面试中被问及快速排序,回来后又看了一次以前做过的案例,说来惭愧,时至今日还需要读好长时间,才能明白自己代码的意思,主要是缺少注释和图解,深有感慨,决定好好记录一下. 之所以使用 ...

  9. 【工业串口和网络软件通讯平台(SuperIO)教程】九.重写通讯接口函数,实现特殊通讯方式

    SuperIO相关资料下载:http://pan.baidu.com/s/1pJ7lZWf 1.1    统一的IO接口 开发一套设备驱动同时具备串口和网络通讯能力,通讯接口在逻辑上是统一的,在此基础 ...

  10. (原)3.4 Zookeeper应用 - 分布式锁

    本文为原创文章,转载请注明出处,谢谢 分布式锁 1.原理 建立表示锁的父节点(图中locker节点) 每个争抢锁的服务器在locker节点下创建有序的临时节点 判断自己是否抢到锁:获取locker下所 ...