您的位置:首页 > 其它

8VC Venture Cup 2016 - Elimination Round-C. Block Towers(二分或暴力+数学)

2016-02-27 22:26 471 查看
C. Block Towers

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of
the students use pieces made of two blocks and m of the students use pieces made of three blocks.

The students don’t want to use too many blocks, but they also want to be unique, so no two students’ towers may contain the same number of blocks. Find the minimum height necessary for the tallest of the students' towers.

Input

The first line of the input contains two space-separated integers n and m (0 ≤ n, m ≤ 1 000 000, n + m > 0) —
the number of students using two-block pieces and the number of students using three-block pieces, respectively.

Output

Print a single integer, denoting the minimum possible height of the tallest tower.

Examples

input
1 3


output
9


input
3 2


output
8


input
5 0


output
10


Note

In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers
of height 3, 6, and 9 blocks.
The tallest tower has a height of 9 blocks.

In the second case, the students can make towers of heights 2, 4,
and 8 with two-block pieces and towers of heights 3 and 6 with
three-block pieces, for a maximum height of 8 blocks.

题意:

给出你n,m两个数,n是要n个2的倍数的数,m是要m个3的倍数的数。要你求刚刚好n+m个数,且2的倍数和3的倍数要是最大中的最小可能的那个数。

思路:

这个题目的思路真是难想到,原来是一个数学题,没想到只是要一个条件就行了,
i/2+i/3-i/6>=n+m&&i/2>=n&&i/3>=m就可以了,这里可以暴力或二分去枚举i出来。

参考文章:http://blog.csdn.net/zwj1452267376/article/details/50664742

AC代码:

#include<iostream>
#include<functional>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
using namespace std;
#define CRL(a) memset(a,0,sizeof(a))
typedef unsigned __int64 LL;
typedef  __int64 ll;
#define CMP bool cmp(const node& a,const node& b){	return a.R<b.R||(a.R==b.R&&a.L<b.L); }
const int T = 503000;
const int mod = 1000000007;

int main()
{
#ifdef zsc
freopen("input.txt","r",stdin);
#endif

int n,m,i,j,k;
int lc,rc,ma;
while(~scanf("%d%d",&n,&m))
{
for(i=2;;i++){
if(i/2+i/3-i/6>=n+m&&i/2>=n&&i/3>=m){
printf("%d\n",i);break;
}
}
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces 模拟