Cc-2022 edited 2 年,9 月前
过第二个用例超时了。。还能在哪里修改吗?
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
struct human
{
int man, women, child;
human(int m,int w,int c):man(m),women(w),child(c){}
};
int main()
{
int t, n, m;
cin >> t;
int order = 0;
while (t--)
{
cin >> n >> m;
int flag = 0;
cout << "case #" << order++ << ':' << endl;
vector<human> humans;
for (int i = 0; i * 3 <= m; i++)
{
for (int j = 0; j * 2 <= m; j++)
{
for (int k = 0; k <= m; k++)
{
if (i * 3 + j * 2 + k == m && i + j + k == n)
{
flag = 1;
humans.push_back(human(i,j,k));
}
}
}
}
if (flag == 0)
{
cout << "-1" << endl;
}
else
{
for (int i = 0; i < humans.size(); i++)
{
cout << humans[i].man << ' ' << humans[i].women << ' ' << humans[i].child << endl;
}
}
}
return 0;
}