我爱随机化
随机化即可通过。
考虑只有两个桶
接下来每次随机一个操作,然后判断是否有两个数有解,每随机
如果多组数据应该就能把随机化卡掉了?
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1010;
unsigned int a[3], b[3];
int edu[N], edv[N], top = 0;
mt19937 rnd(time(0));
void chk(int u, int v)
{
unsigned int x = a[u], y = a[v];
int lat = top;
while(x && y)
{
while(x % 2 == 0 && y % 2 == 0)x /= 2, y /= 2;
if(x % 2 == 0 || y % 2 == 0)break;
edu[++lat] = u;
edv[lat] = v;
if(x > y)x -= y, y *= 2;
else y -= x, x *= 2, swap(edu[lat], edv[lat]);
}
if(x && y)return;
printf("%d\n", lat);
for(int i = 1; i <= lat; i++)printf("%d %d\n", edu[i] + 1, edv[i] + 1);
exit(0);
}
int main()
{
scanf("%d%d%d", a, a + 1, a + 2);
memcpy(b, a, sizeof a);
while(true)
{
memcpy(a, b, sizeof a);
top = 0;
while(a[0]&&a[1]&&a[2]&&top < 900)
{
++top;
edu[top] = rnd() % 3;
edv[top] = rnd() % 3;
if(edu[top] == edv[top])edv[top] = (edv[top] + 1) % 3;
if(a[edu[top]] < a[edv[top]])swap(edu[top], edv[top]);
a[edu[top]] -= a[edv[top]];
a[edv[top]] *= 2;
chk(0, 1);
chk(0, 2);
chk(1, 2);
}
if(!(a[0]&&a[1]&&a[2]))
{
printf("%d\n", top);
for(int i = 1; i <= top; i++)printf("%d %d\n", edu[i] + 1, edv[i] + 1);
return 0;
}
}
return 0;
}