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. fastJson去掉指定字段

    public static String filterFieldsJson(Object src, Class<?> clazz, String... args) { SimpleProp ...

  2. hive学习(八)hive优化

    Hive 优化 1.核心思想: 把Hive SQL 当做Mapreduce程序去优化 以下SQL不会转为Mapreduce来执行 select仅查询本表字段 where仅对本表字段做条件过滤   Ex ...

  3. IEnumerable的几个简单用法

    咋一看到IEnumerable这个接口,我们可能会觉得很神奇,在一般的编程时,基本上我们是想不到去用它的,可是,俗话说得好,存在便是道理,那么,它对我们来说,能够带来哪些奇妙的事情呢? 要想弄懂它,我 ...

  4. 【数据挖掘基础算法】KNN最近邻分类算法

    算法简介: 通过计算待预测样本和已知分类号的训练样本之间的距离来判断该样本属于某个已知分类号的概率.并选取概率最大的分类号来作为待预测样本的分类号 懒惰分类算法,其模型的建立直到待预测实例进行预测时才 ...

  5. js中的for循环

    预定义: var arr=[22,33,12,34];//数组(特殊的对象) var obj={ //对象 name:"Jack", age:"99", sex ...

  6. Vijos1448 校门外的树 [树状数组]

    题目传送门 校门外的树 描述 校门外有很多树,有苹果树,香蕉树,有会扔石头的,有可以吃掉补充体力的……如今学校决定在某个时刻在某一段种上一种树,保证任一时刻不会出现两段相同种类的树,现有两个操作:K= ...

  7. 【Java虚拟机】JVM学习笔记之GC

    JVM学习笔记二之GC GC即垃圾回收,在C++中垃圾回收由程序员自己来做,例如可以用free和delete来回收对象.而在Java中,JVM替程序员来执行垃圾回收的工作,下面看看GC的详细原理和执行 ...

  8. centos7 默认进入系统命令行模式修改

    systemctl get-default  #查看系统启动进入默认模式 systemctl set-default graphical.target #改成默认进入 图形界面模式 systemctl ...

  9. JavaScript with JSONPath

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>JavaScript JSO ...

  10. lambda 表达式+python内置函数

    #函数 def f1(a,b): retrun  a+b #lambda方式,形参(a,b):返回值(a+b) f2=lambda a,b : a+b 在一些比较简单的过程计算就可以用lambda p ...