题解 | #百鸡问题#

百鸡问题

https://ac.nowcoder.com/practice/01d161052db64c249a47fc723b4fd5db

#include <iostream>
#include<bits/stdc++.h>
using namespace std;


int main() {
    int n;
    while (cin >> n) {
	  //注意x,y,z的范围即可,其他无难点
        for (int x = 0; x <=n/5; x++) {
            for (int y = 0 ; y <= n/3; y++) {
                for (int z = 0; z <= n*3; z ++) {
                    if ((x + y + z == 100) && (x * 5 + y * 3 + ceil(z*1.0 / 3)) <= n) {
                        cout << "x=" << x << ",y=" << y << ",z=" << z << endl;
                    }
                }
            }
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

头像
05-12 09:14
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务