您的位置:首页 > 其它

鸡兔同笼

2014-04-18 10:28 239 查看
题目很简单,陷阱还挺多的,首先鸡or兔数目要>=0 ,还有腿的数目必须为偶数个

#include<iostream>
using namespace std;
int main()
{
int N;
cin>>N;
while(N--)
{
int NUM,leg,chicken,rabit;
cin>>NUM>>leg;
chicken=(4*NUM-leg)/2;
rabit=NUM-chicken;
if((chicken>=0&&chicken<=NUM)&&leg%2==0)
cout<<chicken<<" "<<rabit<<endl;
else
cout<<"No answer"<<endl;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: