题目传送门
考察set的用法,可以注意迭代器遍历。
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int sum[2102100];
int a[2102100];
int b[2102100];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--)
{
set<int> s;
int a, b;
cin >> a >> b;
int cnt = 0;
int q = a + b;
if (q % 2)
{
int aa = q / 2 + 1;
int bb = q / 2;
int t = 0;
int lim = 0;
if (bb < a)
{
t = bb + b;
lim = bb - b;
}
else
{
t = aa + a;
lim = aa - a;
}
for (int i = t; i >= lim; i -= 2)
{
s.insert(i);
}
aa = q / 2;
bb = q / 2 + 1;
if (aa < b)
{
t = aa + a;
lim = aa - a;
}
else
{
t = bb + b;
lim = bb - b;
}
for (int i = t; i >= lim; i -= 2)
{
s.insert(i);
}
}else{
int aa = q / 2;
int bb = q / 2;
int t = 0;
int lim = 0;
if (bb < a)
{
t = bb + b;
lim = bb - b;
}
else
{
t = aa + a;
lim = aa - a;
}
for (int i = t; i >= lim; i -= 2)
{
s.insert(i);
}
}
cout << s.size() << endl;
for (set<int>::iterator it = s.begin(); it != s.end(); ++it)
cout << *it << " ";
cout << endl;
}
}