博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4577 X-Boxes
阅读量:5847 次
发布时间:2019-06-18

本文共 2322 字,大约阅读时间需要 7 分钟。

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 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
 
 
 
首先将所有数进行分组:
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了,好方便
 
 
 
1 import java.io.*; 2 import java.math.*; 3 import java.util.*; 4  5 public class Main  6 { 7     public static void main(String[] args) 8     { 9         Scanner cin = new Scanner(new BufferedInputStream(System.in));10         BigInteger n;11         int k;12         int T;13         T = cin.nextInt();14         while(T>0)15         {16             T--;17             n = cin.nextBigInteger();18             k = cin.nextInt();19             int tmp = (1<
0)23 {24 n = n.divide(BigInteger.valueOf(tmp));25 BigInteger tt = n.add(BigInteger.ONE).divide(BigInteger.valueOf(2));26 ans = ans.add(tt);27 }28 System.out.println(ans);29 }30 }31 }

 

 
 
 
 
 
 
 
 

 

 

 

转载地址:http://sfwjx.baihongyu.com/

你可能感兴趣的文章
DoS Attacks Prevention with CBAC
查看>>
Exchange Server 2016 之五:边缘服务器部署
查看>>
Broadcom网卡设置影响HyperV虚拟机网络性能
查看>>
docker讲解和命令汇总
查看>>
SHELL编程四剑客练习--find
查看>>
第一次“初吻” - 和互联网牵手的日子
查看>>
我的友情链接
查看>>
Solr7.1---简单搜索
查看>>
DR方式架设
查看>>
回文串
查看>>
sublime如何安装 package control
查看>>
实战从源码编译LAMP架构+Discuz搭建bbs论坛
查看>>
国外一些 SQL Injection 扫描工具列表
查看>>
foxmai收件箱所有邮件乱码问题解决办法
查看>>
SQL Server海量数据查询代码优化建议
查看>>
case in
查看>>
面向对象-纸牌游戏实验
查看>>
Java面试题总结
查看>>
OA 对象设计
查看>>
音频编码介绍
查看>>