题解:这题会了吗(不懂看看准没事)
2025-01-27 12:30:29
发布于:江西
12阅读
0回复
1点赞
鸡兔同笼
共两种方法
Do you understand the problem of the chicken and the rabbit in the cage?
#include<iostream>
using namespace std;
long long a, b, i, j=0;
int main(){
cin >> a >> b;
i = a;
__方法一:模拟__
while(true){
if (i*2+j*4 == b){
cout << i << endl << j << endl;
break;
}
i--;
j++;
}
__方法二:公式__
//int n = (b-a*2)/2;
//cout << a-n << endl << n;
return 0;
}
这里空空如也
有帮助,赞一个