UVA 714 Copying Books

Source: Internet
Author: User

Original question:
Before the invention of book-printing, it is very hard-make a copy of a book. All the contents had
To is re-written by hand by so called Scribers. The scriber had been given a book and after several
Months he finished its copy. One of the most famous Scribers lived in the 15th century and his name
Was Xaverius endricus Remius Ontius xendrianus (Xerox). Anyway, the work is very annoying and
Boring. And the only-to-speed it up is to hire more scribers.
Once upon a time, there was a theater ensemble the wanted to play famous antique tragedies. The
Scripts of these plays were divided into many books and actors needed more copies of them, of course.
So they hired many scribers to make copies of these books. Imagine you have m books (numbered
,..., m) that is different number of pages (P1,P2,..., pm) and want to make one copy of
Each of them. Your task is to divide these books among K scribes, K≤m. Each book can be assigned
To a single scriber only, and every scriber must get a continuous sequence of books. That means, there
exists an increasing succession of numbers 0 = b0< b1< b2,... < bk−1≤bk= m such that i-th Scriber
Gets a sequence of books with numbers between bi−1+ 1 and BI. The time needed to make a copy of
All the books are determined by the Scriber and who are assigned the most work. Therefore, our goal are to
Minimize the maximum number of pages assigned to a and scriber. Your task is to find the optimal
Assignment.
Input
The input consists of N cases. The first line of the input contains only positive integer N. Then follow
The cases. Each case consists of exactly-lines. At the first line, there is integers m and K,
1≤k≤m≤500. At the second line, there is integers p1,p2,..., pmseparated by spaces. All these
Values is positive and less than 10000000.
Output
For each case, print exactly one line. The line must contain the input succession p1,p2,... pmdivided
into exactly k parts such, the maximum sum of a single part should be as small as possible. Use
The slash character ('/') to separate the parts. There must is exactly one space character between any
Successive numbers and between the number and the slash.
If there is more than one solution, print the one of the minimizes the work assigned to the first Scriber,
Then to the second scriber etc. But each scriber must is assigned at least one book.
Sample Input
2
9 3
100 200 300 400 500 600 700 800 900
5 4
100 100 100) 100 100
Sample Output
100 200 300 400 500/600 700/800 900
100/100/100/100 100

to the general effect:
give you n books, and K-Man, let you divide these books to these people. The last calculated time is when the last person has finished copying. Now let you ask the last person to finish the minimum time. (in the order given, cannot be sorted ...) )

#include <bits/stdc++.h> using namespace std;
Long Long M,k,tot;
int a[510],mark[510];
    BOOL Solve (long long index,int KK)//Whether the condition {long long tmp=0 is satisfied under the Limit value index;
        for (int i=0;i<m;i++) {if (A[i]>index) return false;
            if (kk==1) {tmp=0;
            for (int j=i;j<m;j++) TMP+=A[J];
            if (Tmp<=index) return true;
        else return false;
        } if (Tmp+a[i]<=index) tmp+=a[i];
            else {kk--;
            Tmp=0;
        i--;
}} return true;
    } int main () {Ios::sync_with_stdio (false);
    Long Long t,tmp,seg;
    Long Long l,r,mid;
    cin>>t;
        while (t--) {tmp=tot=0;
        memset (Mark,0,sizeof (Mark));
        cin>>m>>k;
            for (int i=0;i<m;i++) {cin>>a[i];
        Tot+=a[i];
     } if (k==1) {       for (int i=0;i<m;i++) if (i!=m-1) cout<<a[i]<< "";
            else cout<<a[i]<<endl;
        Continue
        } L=0;r=tot;
            while (r-l>1) {mid = (l+r)/2;
            if (Solve (mid,k)) R=mid;
        else L=mid;
} seg=l+1;
        cout<<seg<<endl;
        int q=1;
        Tmp=0;
                for (int i=m-1;i>=0;i--) {if (tmp+a[i]>seg) {mark[i]=1;
                TMP = A[i];
            q++;
            } else tmp+=a[i];
                if (k-q==i+1) {for (int j=0;j<=i;j++) mark[j]=1;
            Break
            }} for (int i=0;i<m-1;i++) {cout<<a[i]<< ""; if (Mark[i]) cout<< '/' << ';
    } cout<<a[m-1]<<endl;
} return 0;

 }

Answer:
Maximizes the minimum, minimizes the maximum, or is the largest, minimizing the average of the general solution is considered by the dichotomy method. This question is also an example of Rujia that small white book. Consider an index value here, if the index can be satisfied to divide the books into K-parts, then the scope of the index to narrow, the idea of the second part of the resulting. First set an upper bound R, is the total number of pages tot, the Nether L is set to 0, if the current index= (L+R)/2 can meet just divided into k parts, R=index otherwise l=index.
The final result returns a SEG value, according to the topic request from the back to the greedy selection, simulation can be ~

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.