POJ 3273 Monthly Expense two points

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=3273

Because of the number of days in a row so greedy before and after the naked two points

Features of the two-part theme:

1. Very easy to write

2. It's easy to write wrong

So pay attention to:

Is the value of the upper and lower bounds too large or too small to add up will explode

Can we finally jump out of the loop

How to adjust the lb and UB after determining the median value

Note that the LB place should be assigned a value of mid+1 otherwise it will be t to die

#include <cstdio>#include<cstdlib>#include<ctime>#include<iostream>#include<cmath>#include<cstring>#include<algorithm>#include<stack>#include<Set>#include<queue>#include<vector>using namespaceStd;typedefLong Longll;Const intMAXN =100010;Const DoubleEPS = 1e-7;intA[MAXN];intMain () {//freopen ("In.txt", "R", stdin);    intN, M; scanf ("%d%d", &n, &m); intMaxnum =0;  for(inti =0; I < n; i++) {scanf ("%d", &A[i]); Maxnum=Max (Maxnum, A[i]); }    intUB =0x3fffffff; intLB =Maxnum;  while(UB >lb) {        intMID = (UB + lb)/2; intCNT =0; intsum =0;  for(inti =0; I < n; i++)        {            if(sum + a[i] >mid) {CNT++; Sum=A[i]; Continue; } Sum+=A[i]; } CNT++; if(CNT <=m) UB=mid; Elselb= Mid +1; } printf ("%d\n", UB); return 0;}

POJ 3273 Monthly Expense 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.