题解 | #百鸡问题#
百鸡问题
https://www.nowcoder.com/practice/01d161052db64c249a47fc723b4fd5db
#include <cstdio> int main(){ int x; int y; float z; int k; // int bigchicken = 5; // int smallchicken = 3; // int otherchicken = 1 / 3; int n; scanf("%d",&n); float sum = 0; while(sum <= n ){ for (x = 0; x <= n / 5 ; ++x) { for (y = 0; y < n / 3 + 1 ; ++y) { for (z = 0; z < 3 * n; ++z) { sum = 5 * x + 3 * y + z / 3; if (sum <= n && x + y + z == 100) { k = z; printf("x=%d,y=%d,z=%d\n", x,y,k); } } } } } }