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 ...
随机推荐
- openjudge-NOI 2.6-2718 移动路线
题目链接:http://noi.openjudge.cn/ch0206/2718/ 题解: 递推,某一个点只能从其左边或者下边走过来 f[i][j]存储(i,j)这个点上的结果,即f[i][j]=f[ ...
- 设计模式之笔记--职责链模式(Chain of Responsibility)
职责链模式(Chain of Responsibility) 定义 职责链模式(Chain of Responsibility),使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系 ...
- 关于boost 的smart_ptr 的使用问题
boost 的smart_ptr 库中含有好几种智能指针,大家用的最多的应该是shared_ptr ,为啥呢?好用,不用管他啥时候会自动删除等等,而且拷贝和复制都很到位, 但实际上,这个库也有问题,连 ...
- Redis 常见面试题
使用Redis有哪些好处? 速度快 基于内存,避免了磁盘I/O的瓶颈. 单进程单线程,减少了线程上下文切换的开销 利用队列技术将并行访问变为串行访问,消除了传统数据库并发访问控制锁的开销. Redis ...
- ISSCC 2017论文导读 Session 14 Deep Learning Processors,A 2.9TOPS/W Deep Convolutional Neural Network
最近ISSCC2017大会刚刚举行,看了关于Deep Learning处理器的Session 14,有一些不错的东西,在这里记录一下. A 2.9TOPS/W Deep Convolutional N ...
- Codeigniter处理用户登录验证后URL跳转
涉及到My_Controller.php以及登录验证模块User.php,代码如下: My_Controller.php class MY_Controller extends CI_Controll ...
- day2 列表中常用的方法
列表中有很多方法,下面来看看常用的方法,我们知道,字符串是以字符列表形式存储的.因此上面学习的字符串中的很多方法在列表中也有. 1.extend() extend()列表的扩展,把两个列表进行 ...
- phpstorm+xdebug远程调试设置
1 xdebug扩展安装 1.1 xdebug扩展安装: 2 服务器PHP配置 3 phpstorm设置 3.1 添加远程debug 3.2 phpstorm设置: 4 浏览器插件安装 4.1 chr ...
- POJ 1976 A Mini Locomotive
$dp$. 要求选择$3$个区间,使得区间和最大.$dp[i][j]$表示前$i$个数中选择了$j$段获得的最大收益. #include <cstdio> #include <cma ...
- GETATTR,DELATTR,SETATTR与GETITEM,SETITEM,DELITEM区别
通过对象.属性的方式触发的是__getattr__,__delattr__,__setattr__ 通过对象['属性']触发__getitem__,__setitem__,__delitem__ cl ...