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
output
input
output
input
output
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代码:
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; }
相关文章推荐
- Transformation 能将 Windows XP/Server 2003 操作系统,完美地模拟成 Windows Vista 的软件
- 用javascript和css模拟select的脚本
- PHP模拟asp.net的StringBuilder类实现方法
- C#使用ImitateLogin模拟登录百度
- javascript用层模拟可移动的小窗口
- 自编jQuery插件实现模拟alert和confirm
- JS模拟按钮点击功能的方法
- PHP模拟asp中response类实现方法
- 模拟Spring的简单实现
- javascript 模拟点击广告
- JQuery中模拟image的ajaxPrefilter与ajaxTransport处理
- php实现模拟post请求用法实例
- JavaScript实现MIPS乘法模拟的方法
- 模拟xcopy的函数
- JS模拟实现Select效果代码
- php模拟服务器实现autoindex效果的方法
- C# SendInput 模拟鼠标操作的实现方法
- PHP模拟登陆163邮箱发邮件及获取通讯录列表的方法
- js实现模拟银行卡账号输入显示效果
- JS模拟并美化的表单控件完整实例