Codeforces 626C Block towers"greedy" two points "mathematical law"

Source: Internet
Author: User

Test instructions

A bunch of people with square Gaeta, there are N people can only add two blocks at a time, there are m individuals can only add three blocks at a time. Everyone is required to cover the height of the tower is not the same, to ensure the minimum number of blocks used, the highest tower height.

0<=n+m 0<=n,m<=1e6

Ideas:

According to the principle of repulsion, if both N and M individuals follow a sequence of 2 or 3, then the number of repetitions should be the smaller of the tower divided by 6, then the Gaeta. At first, I thought I was going to hang on to this idea ...

In fact, the height of the tower is regular. 2 3 4 6 8 9 10 12 ... six in every three, so simply hit the table first, then know N and M, need at least n+m species tower height. Then the two points require the number of towers to make the highest tower heights meet both needs.

#include <bits/stdc++.h>using namespacestd;intbiao[2000050];intBsearch (intLintRintNintm) {    intmid;  while(l<=R) {Mid= (l+r) >>1; if(biao[mid]/2>=n&&biao[mid]/3>=m) {R=mid-1; }        Else{L=mid+1; }    }    returnl;}intMain () { for(intI=1; i<=2000010; i++) {Biao[i]= (I-1)/4*6; if(i%4==1) biao[i]+=2; Else if(i%4==2) biao[i]+=3; Else if(i%4==3) biao[i]+=4; Elsebiao[i]+=6; }    intn,m; CIN>>n>>m; cout<<biao[bsearch (N+m,2000000, N,m)];}

Codeforces 626C Block towers"greedy" two points "mathematical law"

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.