4thweek. P_problemb. Poj1505copy books Two-point method

Source: Internet
Author: User

Main topic:

There is M book, K scribe. The pages of M book are p1,p2......pm .... They started copying at the same time and were working at the same rate. A number of books are required to be assigned to scribes, and the order in which each scribe is to be transcribed must be contiguous.

Please allocate the books so that they complete the transcription task in the least amount of time.

Analysis:

Make the maximum number of pages assigned to each scribe as small as possible. Minimization of maximum value and application of dichotomy method.

Input and output case:

Sample Input
29 3100 200 300 400 500 600 700 800 9005 4100 100 100 100 100

Sample Output
100 200 300 400 500/600 700/800 900100/100/100/100 100

The code is as follows:

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 6 intn,k;7 inta[505];8 Long Longtot;9 intMaxa;Ten  One voidInit () A { -Cin>>n>>K; -tot=0; themaxa=-1; -  for(intI=0; i<n;i++) - { -Cin>>A[i]; +tot+=A[i]; -Maxa=max (A[i],maxa);//the range of explicit maximum page numbers is: [Maxa,tot]. + } A } at  - intDealLong Longnum) - { -     Long LongC=0; -     intsum=1; -      for(intI=0; i<n;i++) in         if(c+a[i]<=num) -c+=A[i]; to         Else +         { -C=A[i]; thesum++; *         } $     returnsum;Panax Notoginseng } -  the voidPrintLong Longnum) + { A     intlast[510]; the    Long LongDone =0; +Memset (Last,0,sizeof(last)); -   intremain =K; $    for(inti = n1; I >=0; i--) $     { -     if(done + a[i] > num | | i+1<remain) -      { theLast[i] =1; -remain--;WuyiDone =A[i]; the      } -     Else WuDone + =A[i]; -  About     } $    for(inti =0; I < n1; i++) -     { -printf"%d", A[i]); -       if(Last[i]) Aprintf"/ "); +     } theprintf"%d\n", a[n-1]); - } $  the voidDo () the { the   Long Longl,r,m; theL=Maxa; -R=tot; in    while(l<R) the   { them=l+ (r-l)/2;//two points, the largest range of copy page number is reduced by half About      if(Deal (m) <=k) r=m;//if the current allocation method can be divided into the number of copies of the number of members of the scribe, the upper limit should be reduced (the interval reduced by half), the      Elsel=m+1;//if the current allocation makes the allocation share larger than the number of scribes, the interval limit is increased to m+1; the   } thePrint (l);//L>=r, this allocation scheme is feasible, the output + } -  the intMain ()Bayi { the     intt,t; theCin>>T; -t=T; -      while(t--) the     { the Init (); the Do (); the     } -     return 0; the}*/


4thweek. P_problemb. Poj1505copy Books. Two Division 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.