Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
58 lines (52 loc) · 1.52 KB

File metadata and controls

58 lines (52 loc) · 1.52 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package tencent;
import java.util.Scanner;
/**
* 贪吃的小Q(递归算法)
*
* 小Q的父母要出差N天,走之前给小Q留下了M块巧克力。小Q决定每天吃的巧克力数量不少于前一天吃的一半,但是他又不想在父母回来之前的某一天没有巧克力吃,请问他第一天最多能吃多少块巧克力
* 输入描述:
* 每个输入包含一个测试用例。
* 每个测试用例的第一行包含两个正整数,表示父母出差的天数N(N<=50000)和巧克力的数量M(N<=M<=100000)。
*
*
* 输出描述:
* 输出一个数表示小Q第一天最多能吃多少块巧克力。
*
* 输入例子1:
* 3 7
*
* 输出例子1:
*/
public class Main4 {
public static void main(String[] args) {
Scanner scanner=new Scanner (System.in);
// int n=scanner.nextInt ();//day
// int m=scanner.nextInt ();//chocolate
int n=1;
int m=12345;
int i = eatChocolate (n, m);
System.out.println (i);
}
public static int eatChocolate(int n,int m){
int mid=m;
while (!isEnough(mid,n,m)){
mid--;
}
return mid;
}
public static boolean isEnough(int mid,int n,int m){
if(mid==1&&n<=m){
return true;
}
if(mid==1&&n>m){
return false;
}
if(n!=0&&m<0){
return false;
}else if(n!=0&&m>=0) {
return isEnough ((int)Math.ceil (mid/2.0),--n,m-mid);
}else {
return true;
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.