题目地址:http://acm.timus.ru/problem.aspx?space=1&num=1155
将A,B,C,D,E,F,G,H一次标记为0,1,2,3,4,5,6,7
相当于涂色问题,用红黑两种颜色去涂,相邻的不能同色,
所以0、2、5、7 相同颜色, 1、3、4、6相同颜色
相同颜色的都可以通过另一种颜色转移,所以当这两种颜色个数之和相等的时候就可以消失,否则不可能
代码如下:
- #include<iostream>
- #include<vector>
- #include<list>
- #include<deque>
- #include<queue>
- #include<stack>
- #include<map>
- #include<set>
- #include<algorithm>
- #include<cstdio>
- #include<cstdlib>
- #include<cstring>
- #include<string>
- #include<cmath>
- using namespace std;
-
- typedef long long LL;
- const int N=3000009;
-
- int a[8];
-
- void move(int x,int y,int t)
- {//将x上面的移到y上面通过t,可以减的就减掉
- while(a[x])
- {
- if(a[t]==0)
- {
- a[t]++;a[y]++;
- printf("%c%c+\n",t+'A',y+'A');
- }
- a[t]--;
- a[x]--;
- printf("%c%c-\n",t+'A',x+'A');
- }
- }
-
- int main()
- {
- int i,j,n;
- for(i=0;i<8;i++)
- scanf("%d",&a[i]);
- int s1=a[0]+a[2]+a[5]+a[7],s2=a[1]+a[3]+a[4]+a[6];
- if(s1!=s2)
- {
- printf("IMPOSSIBLE\n");
- return 0;
- }
-
- move(2,0,1);
- move(5,0,4);
- move(7,0,4);
- move(6,4,5);
- move(1,4,0);
- move(3,4,0);
- while(a[0]--)
- printf("AE-\n");
-
- return 0;
- }