nyoj 94 cigarettes 【水题】

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
 
题意:
           输入一个数T,代表测试样例的个数,然后每个测试样例输入两个数n,k;n代表刚开始有n根香烟,k代表每k根烟头能够形成1根香烟,最终让求他能够吸多少根香烟!

思路:

因为每一根新烟都会产生1根烟头(就算是他又新拼接的新烟也是如此),所以要用刚开始的n根新烟加上n根烟头所能产生的新烟的个数,这n根烟头产生的新烟重新被吸之后还要产生烟头,所以要重新加到烟头的总数上面,然后再进行组装新烟,具体看代码:

//这一道题的题意比较难理解,理解题意后就非常简单了!
#include <stdio.h>
#include <string.h>
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int n,k;
		scanf("%d%d",&n,&k);//n代表开始的时候有n根烟!k代表有k根烟头的话就能够形成一根新烟!
		int t=0;
		int N=n;
		while(n)
		{
			n-=k;
			if(n<0)//应该是<不是<=;
				break;
			t++;
			n++;
		}
		printf("%d\n",N+t);
	}
	return 0;
}
//通过特殊样例得到正确结果:输入:9 3;输出13; 

搜索

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-07-30 03:50:29

nyoj 94 cigarettes 【水题】的相关文章

nyoj 755 山谷 (水题)

题目755 题目信息 运行结果 本题排行 讨论区 山谷 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 八百里伏牛山连绵不断,高低起伏. 家住山脚下的小明开始学习识数了,面朝群山,他想数一下对面有多少山谷,请你写个程序帮他检验一下他数的结果是否正确. 输入 有多组测试数据. 对于每组数据: 第一行: N(2<N<10000) 第二行有N个正整数,分别代表山脉从左到右的高度Hi(0<Hi<1000). 输出 输出每组数据中山谷的个数. 样例输入 3 2

nyoj 1099 Lan Xiang&#39;s Square (水题)

题目1099 题目信息 运行结果 本题排行 讨论区 Lan Xiang's Square 时间限制:1000 ms  |  内存限制:65535 KB 难度:0 描述 Excavator technology which is strong, fast to Shandong to find Lan Xiang. Then the question comes.. :) for this problem , i will give you four points. you just judge

nyoj 1208——水题系列——————【dp】

水题系列 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述     给你一个有向图,每条边都有一定的权值,现在让你从图中的任意一点出发,每次走的边的权值必须必上一次的权值大的情况下,问你最多能走几条边? 输入 首先一个n和m,分别表示点的数目和边的数目接下来m行,每行三个值x,y,val,表示x到y有路,其权值为val.(1<n,m,val<10^5,0<x,y<=n) 输出 输出最多有的边的数目 样例输入 3 3 1 2 1 2 3 1 3 1 1 6

hdu5360 Hiking(水题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Hiking Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 724    Accepted Submission(s): 384Special Judge Problem Description There are 

【Floyd(并非水题orz)】BZOJ4093-[Usaco2013 Dec]Vacation Planning

最近刷水太多标注一下防止它淹没在silver的水题中--我成为了本题,第一个T掉的人QAQ [题目大意] Bovinia设计了连接N (1 < = N < = 20,000)个农场的航班.对于任何航班,指定了其中的k个农场作为枢纽. (1 < = K <= 200 , K < = N). 目前,共有M种单向航班( 1 < = M < = 20,000 ),第i个航班从农场u_i至农场v_i花费d_i ( 1 < = d_i < =10,000 )美元.

BestCoder Round #36 (hdu5199)Gunner(水题)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Gunner Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Long long ago, there is a gunner whose name is Jack. He likes to go hunting very

poj水题-1001 一个简单的大数乘幂算法实现

说到底就是一个大数乘幂运算,小数点后零.明白大数乘幂算法直接搞. 这里就有几个问题: 1.幂位数小可以用二进制容器表示(取模更好,但我是为了练习STL) 2.n位大数用string表示,外加一个int型表示小数点位置 3.字符串×字符串用小学竖式乘法算法就行,注意补零.位数多时两个string两个string地加. 代码长,但理解容易,大数乘法,加法函数很多都能重用. 1 #include <iostream> 2 #include <vector> 3 #include <

水题 ZOJ 3875 Lunch Time

题目传送门 1 /* 2 水题:找排序找中间的价格,若有两个,选价格大的: 3 写的是有点搓:) 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <algorithm> 8 #include <cmath> 9 #include <cstring> 10 #include <string> 11 #include <map> 12 #include <

hdu1240 bfs 水题

原题链接 思路:水题,直接搜 1 #include "map" 2 #include "queue" 3 #include "math.h" 4 #include "stdio.h" 5 #include "string.h" 6 #include "iostream" 7 #include "algorithm" 8 #define abs(x) x > 0