POJ1275 Cashier employee, poj1275cashier

Source: Internet
Author: User
Tags integer numbers

POJ1275 Cashier employee, poj1275cashier

Time Limit:1000 MS   Memory Limit:10000 K
Total Submissions:9078   Accepted:3515
DescriptionA 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 between in the afternoon) to provide good service to its MERs, 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. M ., R (1) shows this number for duration of A.M. to 2: 00. 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. inputThe 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. outputFor each test case, the output shoshould 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
11 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1502322110
Sample Output
1
Source

 

 

Question:

In a supermarket, employees are required to take care of each time. R (I) (0 <= I <24) indicates the number of salesclerks required to end from time I to time I + 1. Now N (N <= 1000) applicants apply for the job, in addition, each applicant has a start time ti. If the first applicant is hired, he will start to work for 8 consecutive hours from the ti moment. It is now required to select some applicants for recruitment, so that the number of I and the number of salespersons at any time can be greater than or equal to R (I ). Find the minimum number of salespersons to be hired.

 

We use $ S [I] $ to represent the $ I + 1 $ employees hired in the previous day,

When $ I >=7 $, we need to meet $ s [I]-s [I-8]> = R [I] $

When $0 <= I <7 $, it is not difficult to find out after being pushed down, we need to meet $ s [I] + s [23]-s [I + 16]> = R [I] $

At the same time, because of the number of people in the question, we also need to meet $0 <= s [I]-s [I-1] <= B [I] $

In this way, this question seems to have been done.

But there are three items on the left of our second formula, but fortunately $ s [23] $ is a constant, and we can solve it in two ways.

Because we want to minimize the number of connections, we need to follow the routine to find the longest path.

 

#include<cstdio>#include<queue>#include<cstring>#define INF 1e8+10using namespace std;const int MAXN=1e5+10;#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=0,f=1;    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}    while(c>='0'&&c<='9'){x=x*10+c-'0';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=1;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,-1,sizeof(head));    memset(vis,0,sizeof(vis));    num=1;}int SPFA(int val){    memset(dis,-0x7f,sizeof(dis));    queue<int>q;    dis[0]=0;    q.push(0);    while(q.size()!=0)    {        int p=q.front();q.pop();        vis[p]=0;        if(p==24&&dis[p]>val) return 0;        for(int i=head[p];i!=-1;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]=1,q.push(edge[i].v);            }        }    }    return dis[24]<=val?1:0;    }int main(){    #ifdef WIN32    freopen("a.in","r",stdin);    #else    #endif    int QWQ=read();    while(QWQ--)    {            memset(pep,0,sizeof(pep));        for(int i=0;i<=23;i++) R[i]=read();        N=read();        for(int i=1;i<=N;i++)             pep[read()]++;        int r=N+1,l=0;        int ans=INF;         while(l<=r)        {            PRE();            int mid=l+r>>1;            for(int i=0;i<=23;i++) AddEdge(i,i+1,0),AddEdge(i+1,i,-pep[i]);            for(int i=7;i<=23;i++) AddEdge(i-7,i+1,R[i]);             AddEdge(0,24,mid);AddEdge(24,0,-mid);            for(int i=0;i<7;i++) AddEdge(i+17,i+1,R[i]-mid);            if(SPFA(mid)) ans=mid,r=mid-1;            else l=mid+1;        }        if(ans>N) printf("No Solution\n");        else printf("%d\n",ans);    }    return 0;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.