POJ1275 cashier employment[differential constraint System | | simplex method]

Source: Internet
Author: User
Tags integer numbers

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

Description

A supermarket in Tehran are open hours a day every day and needs a number of cashiers to fit its need. The supermarket manager has hired your to help him and solve his problem. The problem is and the supermarket needs different number of cashiers at different times of all day (for example, a few Cashiers after midnight, and many in the afternoon) to provide good service to it customers, and he wants to hire the Lea St Number of cashiers for this job.

The manager has provided you and the least number of cashiers needed for every one-hour slots of the day. This data is given as R (0), R (1), ..., R (All): R (0) represents the least number of cashiers needed from midnight to. M., R (1) shows this number for duration of the a.m. to. Note that these numbers is the same every day. There is N qualified applicants for the this job. Each applicant I works non-stop once each hours in a shift of exactly 8 hours starting from a specified hour, say Ti (0 <= ti <=), exactly from the start of the hour mentioned. That's, if the ith applicant is hired, he/she'll work starting from ti o ' clock sharp for 8 hours. Cashiers do not replace one another and work exactly as scheduled, and there is enough cash registers and counters for th OSE who is hired.

You is to write a program to read the R (i) ' s for i=0..23 and TI's for I=1..N that is all, non-negative integer numbers and compute the least number of cashiers needed to being employed to meet the mentioned constraints. Note that there can is more cashiers than the least number needed for a specific slot.

Input

The first line of input was the number of test cases for this problem (at most 20). Each test case is starts with an integer numbers representing the R (0), R (1), ..., R (+) in one line (R (i) can be is at most 100 0). Then there was N, number of applicants in another line (0 <= N <=), after which come n lines each containing One ti (0 <= ti <= 23). There is no blank lines between test cases.

Output

For each test case, the output should are written in one line, and which is the least number of cashiers needed.
If There is no solution for the test case, you should write no solution for the 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

Tehran 2000
a 24-hour supermarket in Tehran needs a group of tellers to meet its needs.            The supermarket manager hired you to help him solve a problem ———— the supermarket needs a different number of tellers at different times of the day (for example, a small batch of midnight and a lot in the afternoon) to provide quality service to the customer and he wants to hire a minimum number of members. The supermarket experience has provided the minimum number of tellers needed per hour of the day ———— R (0), R (1),..., R ( at)。 R0) represents the minimum number of tellers required from midnight to 1:00; R (1) is required between 1:00 and 2:00; Each day, the data is the same. n people apply for the job, each applicant I in 24 hours a day, from a specific time to start a continuous work for exactly 8 hours. Define TI (0<=ti<= atfor the first time mentioned above, that is, if the first applicant is hired, he or she will start working continuously for 8 hours from ti time. Try to write a program that inputs R (i), I=0,..., at, as well as ti,i=1, ..., N, which are all non-negative integers, calculate the minimum number of tellers to employ in order to meet the above restrictions, and at each moment there can be more tellers at work Input Description: The 1th behavior of the input file is an integer t, representing the number of test data in the input file (up to 20). The first behavior of each test data is 24 integers, which represents R (0), R (1),..., R ( at), R (i) can fetch up to 1000. The next line is an integer n, which indicates the number of applicants,0<=n<= +。 Next there are n rows, each of which behaves as an integer ti,0<=ti<= at, there are no blank lines between the test data. Output Description: For each test data in the input file, the output takes up one line, which is the minimum number of tellers that need to be hired. If a test data does not have a solution. The output"No Solution"。
Test Instructions

See after the first reaction: this is not a noi2008 volunteer, but without everyone's spending, minimizing the number of people, the cost is set to 1

A time period a constraint of 24, a person a variable 1000, x for each candidate is not selected, a[i][j]=1 when tj<=i<tj+8 (note time cycle)

Minimize X

Meet constraint Ax<r

Then there are a lot of detail questions:

1. I am on multiple sets of data, initialize a[][] V

2. I can cycle 8 hours in a row, 24 after 1, change (mine is from 1 to 24)

3. I have no solution to the situation, it is not feasible to determine the choice of all

4. I'm going to empty the sum array I'm not using.

Then finally AC, 16ms (0ms), but the difficulty of thinking greatly reduced

#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>using namespaceStd;typedefLong Longll;Const intn= -, m=1005;Const Doubleeps=1e-6, inf=1e9;inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intn= -, m,t;DoubleA[m][n],b[m],c[n],v;intSum[n];voidinit () {memset (A,0,sizeof(a)); memset (SUM,0,sizeof(sum)); V=0.0;}voidPivotintLinte) {B[l]/=A[l][e];  for(intj=1; j<=n;j++)if(j!=e) a[l][j]/=A[l][e]; A[l][e]=1/A[l][e];  for(intI=1; i<=m;i++)if(I!=l&&fabs (a[i][e]) >0) {B[i]-=a[i][e]*B[l];  for(intj=1; 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(intj=1; j<=n;j++)if(j!=e) c[j]-=c[e]*A[l][j]; C[e]=-c[e]*a[l][e];}Doublesimplex () { while(true){        intE=0, l=0;  for(e=1; e<=n;e++)if(c[e]>eps) Break; if(e==n+1)returnv; Doublemn=INF;  for(intI=1; 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)returnINF;//unboundedpivot (l,e); }}BOOLCheck () { for(intI=1; i<=n;i++)if(Sum[i]<c[i])return 0; return 1;}intMain () {//freopen ("In.txt", "R", stdin);    intt=read ();  while(t--) {init ();  for(intI=1; i<=n;i++) c[i]=read (); M=read ();  for(intI=1; i<=m;i++) {T=read () +1;  for(intj=1; j<=8; j + +){                if(t== -) t=1;//printf ("Hi%d\n", t);a[i][t]=1; sum[t]++; T++; } B[i]=1; }        if(!check ()) {Puts ("No Solution");Continue;}        Simplex (); printf ("%d\n",(int) (v+0.5)); }}

POJ1275 cashier employment[differential constraint System | | simplex method]

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.