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"