Block Towers (思维实现)
个人心得:这题没怎么看,题意难懂。后面比完再看的时候发现很好做但是怎么卡时间是个问题。
题意:就是有m个可以用2层积木的,n个可以用三层积木的,但是他们不允许重复所以可以无限添加。
比如 3 2
一开始是2层的开始2,然后 3,然后 4,此时再添加都一样了,为了保证最小高度所以3+3=6,此时的2层的就要添加2个才不重样
网上大神多,这个代码我服,按照函数关系俩着重复的地点都有规律,所以只要找到此时最大m*2,n*3然后碰到一次相同就让最小的最大值增加就可以了
题目:
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.
Example
1 3
9
3 2
8
5 0
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 9blocks. 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.
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
using namespace std;
const int maxn=;
int main()
{
int a,b;
int m,n;
while(cin>>m>>n){
int a=m*,b=n*;
for(int i=;i<=min(a,b);i+=){
if(a<=b) a+=;
else b+=;
}
cout<<max(a,b)<<endl;
}
return ;
}
Block Towers (思维实现)的更多相关文章
- codeforce626C.Block Towers(二分)
C. Block Towers time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces 626C Block Towers(二分)
C. Block Towers time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...
- 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分
C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...
- (二分)Block Towers(cf626)
http://www.codeforces.com/contest/626/problem/C 题意是有一群小朋友在堆房子,现在有n个小孩每次可以放两个积木,m个小孩,每次可以放3个积木,最后每个小孩 ...
- 【CodeForces 626C】Block Towers
题意 给你n,m,如果 n个2的倍数和m个3的倍数,这n+m个数各不相同,那么求最大的数的最小值. 分析 方法1:枚举最大值为i,直到 i/2+i/3-i/6(不重复的2或3的倍数)≥n+m,并且要i ...
- Codeforces 626C Block Towers「贪心」「二分」「数学规律」
题意: 一堆人用方块盖塔,有n个人每次只能加两块方块,有m个人每次只能加三块方块.要求每个人盖的塔的高度都不一样,保证所用方块数最少,求最高的塔的高度. 0<=n+m 0<=n,m< ...
- 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)
题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...
- CodeForces 626C Block Towers
构造AC的.左右两边都先不用6的倍数,然后哪边数字大那一边往回退一下,然后再比较哪边数字大.......直到结束 #include<cstdio> #include<cstring& ...
- CF 327D - Block Tower 数学题 DFS 初看很难,想通了就感觉很简单
D. Block Tower time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
随机推荐
- 手动创建sql数据表
createtable tb ( ID int IDENTITY (1,1) notnull, --创建列ID,并且每次新增一条记录就会加1 WokNo ...
- [CTSC2008]祭祀
题目描述 在遥远的东方,有一个神秘的民族,自称Y族.他们世代居住在水面上,奉龙王为神.每逢重大庆典, Y族都会在水面上举办盛大的祭祀活动.我们可以把Y族居住地水系看成一个由岔口和河道组成的网络.每条河 ...
- Runnable、Callable
Runnable 任务,没有返回值 Callable 任务,又返回值 Runnable与Callable 相同点: 1. 都是接口: 2. 用来编写多线程程序: 3. 都需要调用Thread.star ...
- MapReduce:输入是两个文件,file1代表工厂表,包含工厂名列和地址编号列;file2代表地址表,包含地址名列和地址编号列。要求从输入数据中找出工厂名和地址名的对应关系,输出"工厂名----地址名"表
文件如下: file1: Beijing Red Star Shenzhen Thunder Guangzhou Honda Beijing Rising Guangzhou Development ...
- struts2自定义Interceptor拦截器
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- Mybatis层次结构图
- PHP模拟登录发送闪存
url,post,cookie. 有这三种就可以了. 下面使用Postman模拟发送. 其中,body中是post参数,header中是cookie数据. 下面是php模拟代码. public fun ...
- matplotlib之散点图
环境:windows系统,anaconda3 64位,python 3.6 1.初认识 基本代码如下: import numpy as np import matplotlib.pyplot as p ...
- Java_io__BIO_NIO_AIO
1. http://stevex.blog.51cto.com/4300375/1284437 http://www.cnblogs.com/zhuYears/archive/2012/09/28/2 ...
- java手动分页处理
经常我们在操作数据库的时候都会用到分页,而且很多框架也提供了分页功能,像PageHelper. 但是在有些项目中,需要将数据查询出来进行手动分页,那么原理是什么呢? 其实很简单,首先需要知道数据总量, ...