Cashier Employment_poj1275_差分约束
来源:互联网 发布:手机淘宝联盟何时返利 编辑:程序博客网 时间:2024/06/06 11:43
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.
Analysis
挺难的吧,不看题解做不出来的那种
然后枚举ans的值去建图,spfa
Code
/*ID:wjp13241PROG:cahsierLANG:C++*/#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>#include <stack>#include <queue>#define fo(i,a,b) for (int i=a;i<=b;i++)#define fil(x,t) memset(x,t,sizeof(x))#define STP system("pause")#define min(x,y) x<y?x:y#define max(x,y) x>y?x:y#define ll long long#define INF 0x7f7f7f7f#define EPS 1e-4#define D 25#define E D*D*D+1using namespace std;struct edge{int y,w,next;}e[E];int r[D],s[D],cnt[D],dis[D],t[D],ls[E],maxE=0;bool vis[D];int add(int x,int y,int w){e[++maxE]=(edge){y,w,ls[x]},ls[x]=maxE;}int spfa(int st,int ed){ fil(vis,false); fil(dis,-63); fil(cnt,0); vis[st]=true; dis[st]=0; queue<int>q; q.push(st); while (!q.empty()) { int now=q.front();q.pop(); if (cnt[now]++>D) return -1; for (int i=ls[now];i;i=e[i].next) if (e[i].w+dis[now]>dis[e[i].y]) { dis[e[i].y]=dis[now]+e[i].w; if (!vis[e[i].y]) { vis[e[i].y]=true; q.push(e[i].y); } } vis[now]=false; } return dis[ed];}int main(){ ios::sync_with_stdio(false); int T; cin>>T; while (T--) { fo(i,1,D-1) cin>>r[i]; int n; cin>>n; fil(t,0); fo(i,1,n) { int x; cin>>x; t[x+1]++; } bool flag=false; fo(ans,0,n+1) { fil(ls,0); add(0,24,ans); fo(i,1,D-1) { add(i,i-1,-t[i]); add(i-1,i,0); if (i>8) add(i-8,i,r[i]); else add(i+16,i,r[i]-ans); } if (spfa(0,24)==ans) { flag=true; cout<<ans<<endl; break; } } if (!flag) cout<<"No Solution"<<endl; } return 0;}
- Cashier Employment_poj1275_差分约束
- POJ--1275[Cashier Employment] 差分约束
- POJ1275 Cashier Employment (差分约束)
- poj-1275-Cashier Employment-差分约束
- 【HDU】1529 Cashier Employment 差分约束
- 【差分约束】 HDOJ 1529 Cashier Employment
- poj1275 Cashier Employment (差分约束)
- poj 1275 Cashier Employment 差分约束
- poj1275--Cashier Employment(差分约束)
- ***HDU 1529 - Cashier Employment(差分约束)
- poj1275 Cashier Employment(差分约束)
- Cashier Employment--进阶差分约束系统
- Cashier Employment poj1275(差分约束)
- POJ1275 Cashier Employment (差分约束)
- POJ 1275 Cashier Employment 差分约束
- POJ 1275 Cashier Employment(差分约束系统)
- 1275 Cashier Employment 差分约束系统+BELLMAN
- poj 1275 Cashier Employment(差分约束#6)
- arm 体系架构下 linux kernel 的系统调用与返回 源码分析与总结
- 结构体对齐方式详解
- 全面解析HTTP(一)
- java
- 在Eclipse中查看Java类库的源代码
- Cashier Employment_poj1275_差分约束
- 【POJ 2785 4 Values whose Sum is 0】+ 折半枚举(双项搜索))
- iOS 对折线图的封装
- 重拾python 二十四
- C语言编写停车场系统(有漏洞)
- Matlab的vision toolbox demo调试
- 字符处理
- volatile关键字
- Node.js 学习笔记---1