cigarettes
时间限制:
3000 ms | 内存限制:
65535 KB
难度:
2
描述
-
Tom has many cigarettes. We hypothesized that he has n cigarettes and smokes them
one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette.
Now,do you know how many cigarettes can Tom has?
输入
-
First input is a single line,it's n and stands for there are n testdata.then there are n lines ,each line contains two integer numbers giving the values of n and k.
输出
-
For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter can have.
样例输入
-
3
4 3
10 3
100 5
样例输出
-
5
14
124
来源
-
[rooot]原创
上传者
-
rooot
题目意思是说有n根香烟和每k根香烟可以兑换一根,问他最多可以吸多少根烟,,N组数据
cigarettes
时间限制:
3000 ms | 内存限制:
65535 KB
难度:
2
Tom has many cigarettes. We hypothesized that he has n cigarettes and smokes them
one by one keeping all the butts. Out of k > 1 butts he can roll a new cigarette.
Now,do you know how many cigarettes can Tom has?
-
输入
- First input is a single line,it's n and stands for there are n testdata.then there are n lines ,each line contains two integer numbers giving the values of n and k. 输出
- For each line of input, output one integer number on a separate line giving the maximum number of cigarettes that Peter can have. 样例输入
-
3 4 3 10 3 100 5
样例输出
-
5 14 124
来源
- [rooot]原创 上传者
-
rooot
AC:
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int a,b;
scanf("%d%d",&a,&b);
int sum=a;
int k=a;//第一轮的烟头数就是a
while(k>=b)
{
sum+=k/b;//加上本轮吸的烟数
k=k/b+k%b;//下一轮的烟头数
}
printf("%d\n",sum);
}
}
汽水瓶
时间限制:
1000 ms | 内存限制:
65535 KB
难度:
1
-
描述
-
有这样一道智力题:“某商店规定:三个空汽水瓶可以换一瓶汽水。小张手上有十个空汽水瓶,她最多可以换多少瓶汽水喝?”答案是5瓶,方法如下:先用9个空瓶子换3瓶汽水,喝掉3瓶满的,喝完以后4个空瓶子,用3个再换一瓶,喝掉这瓶满的,这时候剩2个空瓶子。然后你让老板先借给你一瓶汽水,喝掉这瓶满的,喝完以后用3个空瓶子换一瓶满的还给老板。如果小张手上有n个空汽水瓶,最多可以换多少瓶汽水喝?
-
输入
- 输入文件最多包含10组测试数据,每个数据占一行,仅包含一个正整数n(1<=n<=100),表示小张手上的空汽水瓶数。n=0表示输入结束,你的程序不应当处理这一行。 输出
- 对于每组测试数据,输出一行,表示最多可以喝的汽水瓶数。如果一瓶也喝不到,输出0。 样例输入
-
310810
样例输出
-
1540
来源
- 湖南省第六届大学生计算机程序设计竞赛 上传者
- ACM_丁国强
AC:
#include<stdio.h>
int main()
{
int n;
while(scanf("%d",&n)&&n!=0)
{
int sum=n;
int k=n;
while(k>=3)
{
sum+=k/3;
k=k/3+k%3;
}
if(k==2)//两个还可以换一瓶
sum++;
if(n==1||n==0)
printf("0\n");
else
printf("%d\n",sum-n);//这道题一开始是空瓶,所以要减掉
}
}