HDU 4577 X-Boxes
X-Boxes
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 202 Accepted Submission(s): 71
The game is quite simple. There are n balls numbered from 1 to n and k boxes B1, B2,…, Bk satisfying following conditions:
1. With any ball x in box Bi, there must be ball 2x in box Bi+1 if there is a box Bi+1;
2. With any ball x in box Bi, there must be ball y in box Bi-1 satisfying 2y=x if there is a box Bi-1;
3. You can’t put a ball in two different boxes at the same time;
4. Your score is the number of balls in box B1;
5. The player who get the highest score win the game of course.
So, you should tell Crazygirl the highest score she can get.
Each test case has one line containing two integers n and k, meaning that there are n balls and k boxes. ( 1≤n≤1010000, 2≤k≤25 )
10 2
7 5
8 3
0
1
import java.io.*;
import java.math.*;
import java.util.*; public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(new BufferedInputStream(System.in));
BigInteger n;
int k;
int T;
T = cin.nextInt();
while(T>0)
{
T--;
n = cin.nextBigInteger();
k = cin.nextInt();
int tmp = (1<<k);
BigInteger ans = BigInteger.ZERO;
n = n.multiply(BigInteger.valueOf(2));
while(n.compareTo(BigInteger.ZERO) > 0)
{
n = n.divide(BigInteger.valueOf(tmp));
BigInteger tt = n.add(BigInteger.ONE).divide(BigInteger.valueOf(2));
ans = ans.add(tt);
}
System.out.println(ans);
}
}
}
HDU 4577 X-Boxes的更多相关文章
- HDU 6225 Little Boxes
Little Boxes Little boxes on the hillside. Little boxes made of ticky-tacky. Little boxes. Little ...
- HDU 1475 Pushing Boxes
Pushing Boxes Time Limit: 2000ms Memory Limit: 131072KB This problem will be judged on PKU. Original ...
- hdu 4577 X-Boxes 大数
java水过…… 代码如下: import java.math.*; import java.util.*; public class Main { public static void main(S ...
- 2017ACM/ICPC亚洲区沈阳站(部分解题报告)
HDU 6225 Little Boxes 题意 计算四个整数的和 解题思路 使用Java大整数 import java.math.BigInteger; import java.util.Scann ...
- 2017ACM/ICPC亚洲区沈阳站-重现赛
HDU 6222 Heron and His Triangle 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6222 思路: 打表找规律+大数运算 首先我 ...
- HDU 5810 Balls and Boxes(盒子与球)
Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- HDU 5810 Balls and Boxes (找规律)
Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- HDU 5810 Balls and Boxes 数学
Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...
- hdu 4190 Distributing Ballot Boxes(贪心+二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/1000 ...
随机推荐
- highcharts自定义导出文件格式(csv) highcharts的一些使用心得
highcharts是国外的一个图表插件,包括各种数据图形展示,柱形图,线性图等等,是手机端和pc端最好的图表插件之一,相比于百度的echarts更加轻便和易懂.链接http://www.hchart ...
- php判断是手机还是pc访问从而走不同url
<?php header("Content-type:text/html;charset=utf-8"); function is_mobile(){ $user_agent ...
- 自己实现的SVM源码
首先是DATA类 import java.awt.print.Printable; import java.io.File; import java.io.FileNotFoundException; ...
- 【转载】移动开发中的上下左右滑动插件jquery.swipe.js
原文地址http://blog.csdn.net/pvfhv/article/details/3449803/# 源码: (function($) { var old = $.fn.swipe; $. ...
- spring mvc整合mybaitis和log4j
在上一篇博客中,我介绍了在mac os上用idea搭建spring mvc的maven工程,但是一个完整的项目肯定需要数据库和日志管理,下面我就介绍下spring mvc整合mybatis和log4j ...
- ORA-**,oracle 12c操作问题
https://blog.csdn.net/typa01_kk/article/details/41924321
- 基于Token的授权(with srping mvc)
@Override public void doFilter(ServletRequest sr, ServletResponse sr1, FilterChain fc) throws IOExce ...
- C++中对已分配空间的指针调用一个类的构造函数
在看MINIBASE的源代码的时候发现里面有类似于这样的东西 bufTable = (BufDesc*) MINIBASE_SHMEM->malloc( numBuffers * sizeof( ...
- Centos bash: make: command not found
一般出现这个bash: make: command not found提示,是因为安装系统的时候使用的是最小化mini安装,系统没有安装make.vim等常用命令,直接yum安装下即可: yum -y ...
- python中的计时器:timeit
python中的计时器:timeit timeit 通常在一段程序的前后都用上time.time(),然后进行相减就可以得到一段程序的运行时间,不过python提供了更强大的计时库:timeit #导 ...