深圳幻海软件技术有限公司 欢迎您!

Ural 1155 麻烦子 黑书P204

2023-03-22

题目地址: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相同颜

题目地址: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相同颜色

相同颜色的都可以通过另一种颜色转移,所以当这两种颜色个数之和相等的时候就可以消失,否则不可能



代码如下:

  1. #include<iostream>
  2. #include<vector>
  3. #include<list>
  4. #include<deque>
  5. #include<queue>
  6. #include<stack>
  7. #include<map>
  8. #include<set>
  9. #include<algorithm>
  10. #include<cstdio>
  11. #include<cstdlib>
  12. #include<cstring>
  13. #include<string>
  14. #include<cmath>
  15. using namespace std;
  16. typedef long long LL;
  17. const int N=3000009;
  18. int a[8];
  19. void move(int x,int y,int t)
  20. {//将x上面的移到y上面通过t,可以减的就减掉
  21. while(a[x])
  22. {
  23. if(a[t]==0)
  24. {
  25. a[t]++;a[y]++;
  26. printf("%c%c+\n",t+'A',y+'A');
  27. }
  28. a[t]--;
  29. a[x]--;
  30. printf("%c%c-\n",t+'A',x+'A');
  31. }
  32. }
  33. int main()
  34. {
  35. int i,j,n;
  36. for(i=0;i<8;i++)
  37. scanf("%d",&a[i]);
  38. int s1=a[0]+a[2]+a[5]+a[7],s2=a[1]+a[3]+a[4]+a[6];
  39. if(s1!=s2)
  40. {
  41. printf("IMPOSSIBLE\n");
  42. return 0;
  43. }
  44. move(2,0,1);
  45. move(5,0,4);
  46. move(7,0,4);
  47. move(6,4,5);
  48. move(1,4,0);
  49. move(3,4,0);
  50. while(a[0]--)
  51. printf("AE-\n");
  52. return 0;
  53. }