E - Cutting Game FZU - 2268
2017-08-24 14:22
239 查看
Fat brother and Maze are playing a kind of special (hentai) game with a piece of gold of length N where N is an integer. Although, Fat Brother and Maze can buy almost everything in this world (except love) with this gold, but they still think that is not
convenient enough. Just like if they would like to buy the moon with M lengths of the gold, the man who sold the moon need to pay back Fat Brother and Maze N-M lengths of the gold, they hope that they could buy everything they can afford without any change.
So they decide to cut this gold into pieces. Now Fat Brother and Maze would like to know the number of the pieces they need to cut in order to make them fulfill the requirement. The number of the gold pieces should be as small as possible. The length of each
piece of the gold should be an integer after cutting.
Input
The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.
Then T cases follow, each case contains an integer N (1 <= N <= 10^9) indicated the length of the gold.
Output
For each case, output the case number first, and then output the number of the gold pieces they need to cut.
Sample Input
Sample Output
Hint
In the first case, the gold can be cut into 2 pieces with length 1 and 2 in order to buy everything they can afford without change.
写几个就可以发现规律
#include<cstdio>
int main(){
int t,n,i,p=1,sum;
scanf("%d",&t);
while(t--){
scanf("%d",&n);sum=0;
for(i=0;i<31;i++){sum+=1<<i;if(sum>=n)break;}
printf("Case %d: %d\n",p++,i+1);
}
}
convenient enough. Just like if they would like to buy the moon with M lengths of the gold, the man who sold the moon need to pay back Fat Brother and Maze N-M lengths of the gold, they hope that they could buy everything they can afford without any change.
So they decide to cut this gold into pieces. Now Fat Brother and Maze would like to know the number of the pieces they need to cut in order to make them fulfill the requirement. The number of the gold pieces should be as small as possible. The length of each
piece of the gold should be an integer after cutting.
Input
The first line of the data is an integer T (1 <= T <= 100), which is the number of the text cases.
Then T cases follow, each case contains an integer N (1 <= N <= 10^9) indicated the length of the gold.
Output
For each case, output the case number first, and then output the number of the gold pieces they need to cut.
Sample Input
1 3
Sample Output
Case 1: 2
Hint
In the first case, the gold can be cut into 2 pieces with length 1 and 2 in order to buy everything they can afford without change.
写几个就可以发现规律
#include<cstdio>
int main(){
int t,n,i,p=1,sum;
scanf("%d",&t);
while(t--){
scanf("%d",&n);sum=0;
for(i=0;i<31;i++){sum+=1<<i;if(sum>=n)break;}
printf("Case %d: %d\n",p++,i+1);
}
}
相关文章推荐
- FZU Fire Game(两点BFS)
- Fire Game FZU - 2150
- FZU 2275 Game【博弈】
- FZU-Problem 2147 A-B Game
- hdu 2848 Number Cutting Game (递归)
- FZU Fire Game(两点BFS)
- Fire Game FZU - 2150
- Problem_FZU 2150 Fire Game BFS 两点
- 【FZU - 2275 Game】 kmp
- FZU - 2150 K - Fire Game BFS(枚举两点)
- FZU - 2268 Cutting Game
- FZU_Problem 2151 OOXX Game
- fzu2150 Fire Game bfs
- FZU Fire Game(两点BFS)
- FZU 2150 Fire Game bfs
- FZU Problem 2151 OOXX Game (数学啊)
- FZU Easy Game
- FZU - 2147 A-B Game(找规律)
- FZU Fire Game(两点BFS)
- fzu 2150 - Fire Game解题报告