主要的就是一个解决问题的思路
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main ()
{
int N;
cin >> N;
while (N--)
{
int num_elements, num_foot;
cin >> num_elements >> num_foot;
double ans_rabbit = ceil ( (num_foot - 2 * num_elements) / 2.0 ); //注意ceil返回值是double型,但是输出的确实整形
double ans_chicken = ceil ( (4 * num_elements - num_foot) / 2.0 );
// cout << "ans_chicken = " << ans_chicken << " " << "ans_rabbit = " << ans_rabbit << endl;
if (ans_chicken + ans_rabbit == num_elements && ans_rabbit >= 0 && ans_chicken >= 0)
{
cout << ans_chicken << " " << ans_rabbit << endl;
}
else
{
cout << "No answer" << endl;
}
}
return 0;
}