题解 | #汽水瓶#

汽水瓶

https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f

#include <iostream>
using namespace std;

int main() {
    int n;
    while (cin >> n) { // 注意 while 处理多个 case
        if(n == 0) break;
        int one = 0, countB = n;
        while (true) {
            if(countB >= 3){
                one += countB /3;
                countB = countB%3 + countB/3;
            }else if(countB >=2){
                // 借一个空瓶
                countB += 1;
                one += countB/3;
                countB = countB%3 + countB/3;
                countB -= 1;// 还一个空瓶
            }else if(countB < 2){
                break;
            }
        }
        cout << one << endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

不愿透露姓名的神秘牛友
今天 18:02
点赞 评论 收藏
分享
05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务