HDOJ 4577_XMzhou的博客-程序员宝宝

技术标签: JAVA  HDOJ  ACM  

X-Boxes

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


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 B 1, B 2,…, B k satisfying following conditions:
1.  With any ball x in box B i, there must be ball 2x in box B i+1 if there is a box B i+1;
2.  With any ball x in box B i, there must be ball y in box B i-1 satisfying 2y=x if there is a box B i-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 B 1;
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≤10 10000, 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
 
参考了一位大神的写法,看来我的JAVA水平还是有待加强啊!
import java.io.*;
import java.util.*;
import java.math.*;
/**
 *
 * @author XM_zhou
 */
public class Main {
    public static void main(String[] args)
    {
        Scanner cin = new Scanner (new BufferedInputStream(System.in));
        int k , T;
        T = cin.nextInt();
        while(T>0)
        {
            T--;
                BigInteger 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);
                
        }
      
    }
}   


版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/zkzxmzk/article/details/9930057

智能推荐

eclipse环境变量配置及及其他相关错误总结_eclipse配置环境变量出现错误_test_one1的博客-程序员宝宝

在安装eclipse的路上真的是路过十万八千里,今天就把遇到的“妖怪”一一罗列出来 1.环境变量配置 jdk的环境变量配置 现在是只配置一个JAVA_HOME(jdk的路径)就行了,配置完jdk的环境变量之后在path的最前面加上“;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin” 验证是否配置jdk环境

adb启动应用_adb 关闭应用_wuzuyu365的博客-程序员宝宝

eclipse编译安装app时,是自己启动了,而打了系统签名后的apk安装后,要主动启动,命令行方式启动,例如adb shell  am   start com.photocomb.server/com.photocomb.ui.LaunchActivity更多: 在Android中,除了从界面上启动程序之外,还可以从命令行启动程序,使用的是命令行工具am.

墨者学院-SQL过滤字符后手工注入漏洞测试(第1题)_weixin_38131137的博客-程序员宝宝

这题一试验就清楚是被过滤了,在这里有几点提示的1、如果是空格、=的过滤,用/**/ 与 like替换2、这里里面有坑,百度后才发现,url编码存在简单模式和复杂模式3、下载个小葵,或者用编码网站http://web.chacuo.net/charseturlencode4、后续发现再补...

jsp&el&jstl_jsp & el & jstl_JasonZii的博客-程序员宝宝

一、JSP技术1.jsp脚本和注释jsp脚本:1) ----- 内部的java代码翻译到service方法的内部2) ----- 会被翻译成service方法内部out.print()3) ---- 会被翻译成servlet的成员的内容 jsp注释: 不同的注释可见范围是不同1)Html注释:---可见范围 jsp源码、翻译后的servlet、页面         

使用webpack构建项目_如何使用WEBPACK构建现代应用程序_cumifi2519的博客-程序员宝宝

使用webpack构建项目How far can we get with Webpack’s default configuration? Webpack的默认配置能达到多远? I had the privilege of speaking at GDG Devfest last month with a talk that was centered around using webpack i...

架构之路_十一种行为型设计模式_沉默的舞台剧的博客-程序员宝宝

一、责任链模式1.11.21.31.4二、命令模式2.12.22.32.4三、迭代器模式3.13.23.33.4四、中介者模式4.14.24.34.4五、备忘录模式5.15.25.35.4六、观察者模式6.16.26.36.4七、状态模式7.17.27.37.4八、策略模式8.18.28.38.4九、模板方法模式9.19.29.39.4十、访问者模式10.110.210.310.4...

随便推点

使用Windbg查看CrashDump_crashdump +0x偏移 定位行数_远行的风的博客-程序员宝宝

本文介绍如何使用Windbg简单查看Windows Crash Dump.WWindbgsymbol配置:SRV*D:\Symbols*http://msdl.microsoft.com/download/symbols 载入CrashDump的dmp文件 载入后,执行!analyze-v: 相关的参数说明:FAULTIN

Python通过kerberos安全认证操作kafka_python kerberos_小竹筒的博客-程序员宝宝

【坑】Python通过kerberos安全认证操作kafka如何通过Kerberos认证.1.安装Kerberos客户端CentOS:yum install krb5-workstation使用which kinit查看是否安装成功;2.拷贝Kerberos配置文件conf目录下krb5.conf和kafka.keytab和jaas.conf拷贝到客户端机器的etc目录, ...

python音频分析(一)绘制wav的时域频域图_kezis的博客-程序员宝宝

python音频分析(一)绘制wav的时域频域图一.引入时域图:x轴为时间,y轴为振幅频域图:x轴为频率,y轴为振幅(上述频域图为线性振幅谱,还另有对数振幅谱、自功率谱,y轴不是单纯振幅)时域与频域的直观关系见下图二.画时域图1.读入wav文件(pyaudio.PyAudio)2.波形数据转换为数组(numpy.frombuffer )3.构建横坐标(numpy.aran...

Modbus介绍与函数使用及项目示例_modbus库函数_小辫洋的博客-程序员宝宝

简介Modbus与函数使用,通过程序项目演示帮助更清晰理解

利用Modbus库编程实现采集传感器数据和控制硬件设备_传感器modbus数据采集_Summer_taotao的博客-程序员宝宝

利用Modbus库,编程实现采集传感器数据和控制硬件设备(传感器和硬件通过slave模拟)

timestamp 详解_timestamp 应用mid不能为空且有效期为10分钟_天天向尚6的博客-程序员宝宝

每一个数据库都有一个计数器,这个计数器记录着数据行的插入、更新行为。如果我们为一个表中增加 timestamp 列,那么,该列将记录每一个数据行的计数器值。假如数据库中当前的计数器是 20(实际中不是数字类型,为了方便解释,这里用数字类型):那么在表 A 中插入一条记录后,插入行的 timestamp 为 21;然后更新表 B 的一条记录后,更新行的 timestamp 为 22;现在再更新刚