AcWing 4461. 范围分区
原题链接
简单
作者:
Coinisi.
,
2023-01-25 12:07:07
,
所有人可见
,
阅读 131
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#define IOS std::ios::sync_with_stdio(false)
#define pb push_back
#define inf 0x3f3f3f3f
#define YES cout << "YES" << endl;
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define NO cout << "NO" << endl;
#define int long long
#define x first
#define y second
#define cmp [&](PII a, PII b){ return a.y < b.y; }
const int N = 5e5+10, mod = 1e9+7, M = 1e6+5, K = 1e5+10, Z = 2e5+7;
using namespace std;
typedef long long LL;
typedef priority_queue<int> PQI;
typedef priority_queue <int, vector<int>, greater<>> PQGI;
typedef pair<int, int> PII;
int t, st[5010], tt;
int get_sum(int n)
{
int sum = 0;
for(int i = 1; i <= n; i ++)
sum += i;
return sum;
}
void solve()
{
t ++, tt = 0;
memset(st, 0, sizeof st);
int n, x, y; cin >> n >> x >> y;
int sum = get_sum(n), s = x + y;
if(sum % s == 0)
{
cout << "Case #" << t << ':' << " POSSIBLE" << endl;
int h1 = sum / s * y, h2 = sum - h1;
if(h2 <= n) {cout << 1 << endl << h2 << endl; return;}
else
{
for(int i = n; i >= 1; i --)
{
if(i > h2) continue;
h2 = h2 - i, st[++ tt] = i;
if(h2 <= i - 1) {st[++ tt] = h2; break;}
else continue;
}
}
cout << tt << endl;
for(int i = 1; i <= tt; i ++) cout << st[i] << ' ';
cout << endl;
}
else if(sum % s != 0)
cout << "Case #" << t << ':' << " IMPOSSIBLE" << endl;
return;
}
signed main()
{
IOS; cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
cin >> T;
while( T -- ) solve();
return 0;
}