Lightoj 1048-conquering Keokradong "two points"

Source: Internet
Author: User

Title Link: http://www.lightoj.com/volume_showproblem.php?problem=1048

Test instructions: There are N numbers, which are divided into M parts in order, M<=min (n,300). So that the maximum value of each share is minimized. There are a lot of cases in which the first day, the next day ... And the biggest case.

Idea: Two of the largest and, get a few mid. Determine if the condition is met.

Code: (No AC really can not find out, first put)

#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include <string>#include <functional>#include <iterator>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <set>#include <map>#include <list>#include <bitset>#include <sstream>#include <iomanip>#include <fstream>#include <iostream>#include <ctime>#include <cmath>#include <cstring>#include <cstdio>#include <time.h>#include <ctype.h>#include <string.h>#include <assert.h>using namespace STD;inta[1010];intTintN, K;inttmpintsum[1010];intAnsintg[1010];intIS_OK (intx) {intResintnum =0;intpos =0; for(inti =1; I <= N; i++)if(Sum[i]-sum[i-1] > x)return 0; for(inti =1; I <= N; i++) {if(Sum[i]-sum[pos] = = X | | (i = = n && sum[i]-sum[pos] <= x) | | (I! = n && sum[i+1]-Sum[pos] > x)) {if(I! = n) num++;        pos = i; }    }if(Num <= k)return 1;Else return 0;}voidGet_ans () {intResintnow =1;intremain = N-k-1; while(now <= N) {intpos = Now-1;intTMP = Sum[now]-sum[now-1]; now++;if(Remain! =0)        { for(; now <= N; now++) {if(Sum[now]-sum[pos] <= ans) tmp = Sum[now]-Sum[pos], remain--;Else{printf("%d\n", TMP); Break; }            }if(Remain = =0)            {printf("%d\n", TMP); now++; Break; }        }Else{printf("%d\n", TMP); }    }}intMain () {scanf("%d", &t);intCases =1; while(t--) {scanf("%d%d", &n, &k); n++;inttot =0;memset(Sum,0,sizeof(sum)); for(inti =1; I <= N; i++) {scanf("%d", &a[i]); Sum[i] = sum[i-1] + a[i];        Tot + = A[i]; }intleft =1;intright = tot;intMid while(left <= right) {mid = (left + right)/2;if(Is_ok (mid))                {ans = mid; right = mid-1; }ElseLeft = mid +1; }printf("Case%d:", cases++);printf("%d\n", ans);    Get_ans (); }return 0; }

Copyright NOTICE: Reprint please indicate the source.

Lightoj 1048-conquering Keokradong "two points"

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.