2252: Pick Balls
| Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
|---|---|---|---|---|---|
| | 3s | 8192K | 397 | 169 | Standard |
Assume that the number of balls she picks last time is N,then she can only pick N, N/2 or N*2 balls this time. She can pick only one ball at the beginning. Of course, when N is equal to 1, she can not pick 0 ball this time.
Certainly she can always do that successfully no matter what value M is.But, to make it more difficult, she wants to use the fewest times to finish the task.
Could you help her? Thank you.:)
Input
The end of the input will be indicated by an integer value of zero.
Output
Sample Input
2
3
0
8
Sample Output
2
2
4
hints:
2: 1 1
3: 1 2
2 4
8: 1 1
Problem Source: chihao
This problem is used for contest: 34
Submit / Problem List / Status / Discuss
#include<iostream>
#include<stdio.h>
using namespace std;
int store[32];
int main()
{
int n;
for(int i=0;i<31;i++)
{
store[i]=(1<<i);
}
while(scanf("%d",&n),n)
{
int count=0;
for(int i=0;i<31;i++)
{
if(n<store[i])break;
count++;
n=n-store[i];
}
if(n>0)
for(int i=30;i>=0;i--)
{
if(n>=store[i])
{
n=n-store[i];
count++;
}
}
if(n==0)
cout<<count<<endl;
}
return 0;
}
本文介绍了一款新版judge系统,通过支持特殊判断、提交后状态页面及语言检查来解决内存越界导致的Waiting问题。具体案例:挑球任务,要求学生用最少次数从袋中取出所有球,遵循特定规则。输入为总球数,输出为完成任务所需的最小次数。此问题由吉林大学学生提出,并包含实例输入输出,旨在帮助学生理解并解决复杂编程问题。
334

被折叠的 条评论
为什么被折叠?



