首页 > 其他分享 >Block Towers

Block Towers

时间:2022-11-07 15:32:13浏览次数:46  
标签:blocks Towers mid long pieces students block Block


题目:
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.
题解:
二分

#include <bits/stdc++.h>
using namespace std;
bool check(long long mid,long long n,long long m){
return mid/2>=n&&mid/3>=m&&mid/2+mid/3-mid/6>=n+m;
}
int main()
{
long long n,m;
cin>>n>>m;
long long l=0,r=1e12;
long long ans=1e12;
while(l<r){
long long mid=(l+r)/2;
if(check(mid,n,m)) r=mid,ans=min(ans,mid);
else l=mid+1;
}
cout<<ans<<endl;
return 0;
}


标签:blocks,Towers,mid,long,pieces,students,block,Block
From: https://blog.51cto.com/u_15866659/5829928

相关文章

  • 阻塞队列 - BlockingQueue
     线程通信的一个工具。在任意时刻,不管并发有多高,在单JVM上面,同一时间永远只有一个线程能够对队列进行入队或者出队操作。1.线程安全的队列;2.队列类型:无限队列、有限队......
  • ORACLE新参数MAX_IDLE_TIME和MAX_IDLE_BLOCKING_TIME简介
    Oracle12.2引入了新参数MAX_IDLE_TIME。它可以指定会话空闲的最大分钟数。如果会话空闲的时间超过了这个阈值的话,这个会话将会被自动终止。其实在Oracle10g&11g时代,我......
  • CF1141F2 Same Sum Blocks (Hard)
    题目传送门思路简单题。不妨先预处理出每一个区间的\(\sum\),然后离散化\(\sum\),对于每个\(\sum\)开一个\(\mathcalvector\)记录所有区间的左右端点。然后枚举每......
  • 11g Active Dataguard的Automatic Block Repair特性
    11g出来这么多年了,虽然早就知道这个特性,但一直也没有亲自测试一下,今天正好有业务需求,简单测试了下,记录之。1.在主库中创建测试用户和测试表(test.adg):createusertesti......
  • li标签设置inline-block后元素间产生间隙
    参考文章li与li之间设置display:inline-block;后有看不见的空白间隔如何形成的,相应的解决办法1.问题描述当使用li作为导航栏时,通常需要将li设置为一行显示,其......
  • Rust依赖下载慢+Blocking
    覆盖默认的镜像地址~~直接使用新注册服务来替代默认的~~crates.io。在$HOME/.cargo/config.toml添加以下内容:[source.crates-io]replace-with='ustc'[source.us......
  • HCIE-FusionBlock分布式块存储
    FusionStorageBlock分布式块存储华为存储分类全闪存(OceanStorDorado)混合闪存(OceanStorV3、OceanStorV5)边缘数据存储(FusionCube)分布式存储(OceanStor100D)......
  • ThreadPoolExecutor BlockingQueue讲解
    有四种常用阻塞队列策略:1.直接拒绝:(DirectHandoffs)一个好的工作队列应该是不缓存任务,而是直接交给线程处理,就如SynchronousQueue一样。一个任务将会入队失败,如果没有......
  • Linux下磁盘管理工具:hdparm/iostat/parted/fdiisk/badblocks/smartctl/losetup/sg3_ut
    一、hdparm:    hdparm可以检测,显示与设定IDE,SCSI,SATA,SAS硬盘的硬件参数,    如:hdparm-I/dev/sdc可以获取sdc的硬件信息    hdparm-W0/de......
  • 【USACO10JAN】Cheese Towers S 奶酪塔 (背包dp)
    一种思路奇特的做法。看到题目容易联想到背包dp,因为看上去很像。但是我们并不知道上面有没有大奶酪。所以我们不妨倒过来看,从上往下加奶酪。设\(dp(i,1/0)\)表示当前......