zoukankan      html  css  js  c++  java
  • nyoj 94-cigarettes (分清楚,那一部分的cigarettes是用过的,那一部分是没有用过的)

    94-cigarettes


    内存限制:64MB 时间限制:3000ms 特判: No
    通过数:13 提交数:20 难度: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

    C/C++ AC
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <cmath>
     6 #include <stack>
     7 #include <set>
     8 #include <map>
     9 #include <queue>
    10 #include <climits>
    11 
    12 using namespace std;
    13 const int MAX = 1e6 + 10;
    14 int n, a, b;
    15 
    16 int main()
    17 {
    18     cin >>n;
    19     while (n --)
    20     {
    21         int ans = 0, temp;
    22         scanf("%d%d", &a, &b);
    23 
    24         while (a >= b)
    25         {
    26             temp = a / b;
    27             ans += temp * b; // temp * b 表示已经用过的
    28             a = temp + a % b;
    29         }
    30         ans += a;
    31         printf("%d
    ", ans);
    32     }
    33 }
  • 相关阅读:
    数据库知识点
    hibernate5--主键生成策略
    hibernate5学习知识点小结
    hibernate5小案例讲解
    hibernate5新手跳过的坑
    strut2_struts.xml文件配置知识点汇集
    在使用ElementUI的JSP项目中,集成富文本编辑器QuillEditor
    如何在JSP中使用VUE/elementUI
    Java定时任务--Timer和TimerTask
    SecureFX的破解问题
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9320622.html
Copyright © 2011-2022 走看看