X-Boxes

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 202    Accepted Submission(s): 71

Problem Description
Crazygirl is a crazy fan of XBOX games. Today, she’s here middle in a competition, in which the winner will be rewarded with an opportunity of working in the XBOX Company as a game testing player. Now, here comes the final game. As Cazygirl get a draw with the other competitor, Lich King, she must beat Lich this time.
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.

 
Input
The first line is the number of test cases.
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 )
 
Output
For each test case, output one line that contains an integer equals to the highest score you can get.
 
Sample Input
3
10 2
7 5
8 3
 
Sample Output
4
0
1
 
Source
 
 
 
首先将所有数进行分组:
1 2 4 8 16 ......
3 6 12 24 48.....
5 10 20 40 80.....
.....
 
 
 
其实就是奇数的2^n倍。
 
 
 
可以放在1的相当于是(2*a-1)*2^(k*t-1) <= n
 
 
然后枚举t,求多少个a满足。‘’
 
 
这题很卡时间,C++写的大数TLE到现在。
 
JAVA一写就过了,以后多学着使用JAVA了,好方便
 
 
 
 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的更多相关文章

  1. HDU 6225 Little Boxes

    Little Boxes Little boxes on the hillside.  Little boxes made of ticky-tacky.  Little boxes.  Little ...

  2. HDU 1475 Pushing Boxes

    Pushing Boxes Time Limit: 2000ms Memory Limit: 131072KB This problem will be judged on PKU. Original ...

  3. hdu 4577 X-Boxes 大数

    java水过…… 代码如下: import java.math.*; import java.util.*; public class Main { public static void main(S ...

  4. 2017ACM/ICPC亚洲区沈阳站(部分解题报告)

    HDU 6225 Little Boxes 题意 计算四个整数的和 解题思路 使用Java大整数 import java.math.BigInteger; import java.util.Scann ...

  5. 2017ACM/ICPC亚洲区沈阳站-重现赛

    HDU 6222 Heron and His Triangle 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6222 思路: 打表找规律+大数运算 首先我 ...

  6. HDU 5810 Balls and Boxes(盒子与球)

     Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  7. HDU 5810 Balls and Boxes (找规律)

    Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  8. HDU 5810 Balls and Boxes 数学

    Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  9. hdu 4190 Distributing Ballot Boxes(贪心+二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/1000 ...

随机推荐

  1. 017 CPU冲高定位方法

    1.通过top命令查看cpu占用高的进程ID; 2.通过top -Hp 进程ID 查看该进程下所有线程占用cpu的情况,拿出占用cpu最高的线程ID,换算成十六进制; 3.通过 jstack 进程ID ...

  2. Python 类的名称空间和组合

    一.Python类的名称空间 class Student(object): School = '北京大学' def __init__(self): pass stu1 = Student() stu1 ...

  3. java并发-同步容器类

    java平台类库包含了丰富的并发基础构建模块,如线程安全的容器类以及各种用于协调多个相互协作的线程控制流的同步工具类. 同步容器类 同步容器类包括Vector和Hashtable,是早期JDK的一部分 ...

  4. Caffe学习系列(8):solver,train_val.prototxt,deploy.prototxt及其配置

    solver是caffe的核心. net: "examples/mnist/lenet_train_test.prototxt" test_iter: 100 test_inter ...

  5. Java容器---Collection接口中的共有方法

    1.Collection 接口 (1)Collection的超级接口是Iterable (2)Collection常用的子对象有:Map.List.Set.Queue. 右图中实现黑框的ArrayLi ...

  6. csu 1767(循环节)

    1767: 想打架吗?算我一个!所有人,都过来!(2) Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 99  Solved: 18[Submit][St ...

  7. 简易web-slide

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. MINIBASE源代码阅读笔记之HFPage

    HFPage heap file的page的类 成员 slot_t:用来表示页里的slot,包括offset和length slot[]:倒着生长的slot array slotCnt:有多少已用sl ...

  9. codeforce 1A Theatre Square

    A. Theatre Square Theatre Square in the capital city of Berland has a rectangular shape with the siz ...

  10. poj3414 Pots(BFS)

    题目链接 http://poj.org/problem?id=3414 题意 有两个杯子,容量分别为A升,B升,可以向杯子里倒满水,将杯子里的水倒空,将一个杯子里的水倒到另一个杯子里,求怎样倒才能使其 ...