1155. Troubleduons

Time limit: 0.5 second
Memory limit: 64 MB
Archangel of the Science is reporting:
“O, Lord! Those physicists on the Earth have discovered a new elementary particle!”
“No problem, we’ll add another parameter to the General Equation of the Universe.”
As physics develops and moves on, scientists find more and more strange elementary particles, whose properties are more than unknown. You may have heard about muons, gluons and other strange particles. Recently scientists have found new elementary particles called troubleduons. These particles are called this way because scientists can create or annihilate them only in couples. Besides, troubleduons cause trouble to scientists, and that’s why the latter want to get rid of them. You should help scientists get rid of troubleduons.
Experimental set consists of eight cameras, situated in the vertices of a cube. Cameras are named as A, B, C, …, H. It is possible to generate or annihilate two troubleduons in neighbouring cameras. You should automate the process of removing troubleduons.

Input

The only line contain eight integers ranging from 0 to 100, representing number of troubleduons in each camera of experimental set.

Output

Output sequence of actions leading to annihilating all troubleduons or “IMPOSSIBLE”, if you cannot do it. Actions should be described one after another, each in a separate line, in the following way: name of the first camera, name of the second camera (it should be a neighborough to the first one), “+” if you create troubleduons, “-” if you destroy them. Number of actions in the sequence should not exceed 1000.

Samples

input output
  1. 1 0 1 0 3 1 0 0
  1. EF-
  2. EA-
  3. AD+
  4. AE-
  5. DC-
  1. 0 1 0 1 2 3 2 2
  1. IMPOSSIBLE
Problem Source: Ural Collegiate Programming Contest, April 2001, Perm, English Round 
Difficulty: 468
 
题意:一个正方体,八个顶点各有一些颗粒在上面,每次相邻的两个点可以同时增加或消去一个颗粒,问让你给出一个操作序列把全部颗粒消去。
分析:显然,肯定先消去相邻的,知道不能消去为止。
按照这个思路,最后是要把点先增加再消去
我们发现互不相邻的点上的颗粒可以通过先增加,再消去的操作移动
比如a,0,c  ->  a+c, c, c -> a, 0, 0
就是这样。。。。
然后题目并没有要求最短操作序列。。。
所以我们把颗粒全都移到相邻的两个点上再消去就好。
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <deque>
  6. #include <vector>
  7. #include <queue>
  8. #include <iostream>
  9. #include <algorithm>
  10. #include <map>
  11. #include <set>
  12. #include <ctime>
  13. using namespace std;
  14. typedef long long LL;
  15. typedef double DB;
  16. #define For(i, s, t) for(int i = (s); i <= (t); i++)
  17. #define Ford(i, s, t) for(int i = (s); i >= (t); i--)
  18. #define Rep(i, t) for(int i = (0); i < (t); i++)
  19. #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
  20. #define rep(i, x, t) for(int i = (x); i < (t); i++)
  21. #define MIT (2147483647)
  22. #define INF (1000000001)
  23. #define MLL (1000000000000000001LL)
  24. #define sz(x) ((int) (x).size())
  25. #define clr(x, y) memset(x, y, sizeof(x))
  26. #define puf push_front
  27. #define pub push_back
  28. #define pof pop_front
  29. #define pob pop_back
  30. #define ft first
  31. #define sd second
  32. #define mk make_pair
  33. inline void SetIO(string Name) {
  34. string Input = Name+".in",
  35. Output = Name+".out";
  36. freopen(Input.c_str(), "r", stdin),
  37. freopen(Output.c_str(), "w", stdout);
  38. }
  39.  
  40. inline int Getint() {
  41. int Ret = ;
  42. char Ch = ' ';
  43. while(!(Ch >= '' && Ch <= '')) Ch = getchar();
  44. while(Ch >= '' && Ch <= '') {
  45. Ret = Ret*+Ch-'';
  46. Ch = getchar();
  47. }
  48. return Ret;
  49. }
  50.  
  51. const int N = , Left[] = {, , , }, Right[] = {, , , };
  52. int Arr[N];
  53.  
  54. inline void Input() {
  55. Rep(i, ) scanf("%d", Arr+i);
  56. }
  57.  
  58. inline void Create(int x, int y) {
  59. Arr[x]++, Arr[y]++;
  60. printf("%c%c+\n", 'A'+x, 'A'+y);
  61. }
  62.  
  63. inline void Destroy(int x, int y) {
  64. Arr[x]--, Arr[y]--;
  65. printf("%c%c-\n", 'A'+x, 'A'+y);
  66. }
  67.  
  68. inline void Move(int St, int Ed) {
  69. int Tmp;
  70. if(!Ed && St < ) Tmp = ;
  71. else if(!Ed) Tmp = ;
  72. else if(St > ) Tmp = ;
  73. else Tmp = ;
  74. while(Arr[St]) {
  75. if(!Arr[Tmp]) Create(Tmp, Ed);
  76. Destroy(Tmp, St);
  77. }
  78. }
  79.  
  80. inline void Solve() {
  81. int a = , b = ;
  82. Rep(i, ) a += Arr[Left[i]], b += Arr[Right[i]];
  83. if(a != b) puts("IMPOSSIBLE");
  84. else {
  85. Rep(i, )
  86. if(Left[i]) Move(Left[i], );
  87. Rep(i, )
  88. if(Right[i] != ) Move(Right[i], );
  89. while(Arr[]) Destroy(, );
  90. }
  91. }
  92.  
  93. int main() {
  94. #ifndef ONLINE_JUDGE
  95. SetIO("F");
  96. #endif
  97. Input();
  98. Solve();
  99. return ;
  100. }

ural 1155. Troubleduons的更多相关文章

  1. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  2. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  3. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  4. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  5. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  6. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

  7. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

  8. ural 2066. Simple Expression

    2066. Simple Expression Time limit: 1.0 secondMemory limit: 64 MB You probably know that Alex is a v ...

  9. ural 2065. Different Sums

    2065. Different Sums Time limit: 1.0 secondMemory limit: 64 MB Alex is a very serious mathematician ...

随机推荐

  1. java笔记--关于int和byte[]的转换

    关于int和byte[]数组的转换 --如果朋友您想转载本文章请注明转载地址"http://www.cnblogs.com/XHJT/p/3891747.html "谢谢-- 众所 ...

  2. HNU 12826 Balloons Colors

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12826&courseid=268 #include&l ...

  3. 疯狂抨击ie6下各种扭曲行为

    从开始接触ie6就被它强大的力量给震住了,虽然它很可怕,但是我总归得想方设法把它给扼杀在摇篮外.以下是我在ie6下面碰到的一些扭曲行为,弱弱的把它给干掉!!! 1.浮动下margin翻倍问题(很典型, ...

  4. 15 day 1代碼

    第一题 用堆维护. #include <cstdio> #include <algorithm> #include <queue> int n,i,f[400000 ...

  5. SSM框架Web程序的流程(Spring SpringMVC Mybatis)

    SSM框架的Web程序主要用到了三个技术: Spring:用到了注解和自动装配,就是Spring的两个精髓IOC(反向控制)和 AOP(面向切面编程). SpringMVC:用到了MVC模型,将逻辑代 ...

  6. Ubuntu14.04server开放rootssh登录权限

    刚安装了Ubuntu 14.04 server的虚拟机,普通帐号可以远程登录,但是root不行,输入密码后一直报错: permission denied 最后发现ssh的配置(/etc/ssh/ssh ...

  7. 使用shadow dom封装web组件

    什么是shadow dom? 首先我们先来看看它长什么样子.在HTML5中,我们只用写如下简单的两行代码,就可以通过 <video> 标签来创建一个浏览器自带的视频播放器控件. <v ...

  8. Windows远程桌面连接如何直接使用剪贴板功能

    连接到Windows Server服务器时,通常使用远程桌面连接,那么如果有些时候按照习惯复制本地文件到远程服务器发现无法粘贴怎么办,这个时候稍微设置一下就OK了, 首先重新运行远程桌面连接,在登陆界 ...

  9. (原创)Python文件与文件系统系列(4)——文件描述字操作

    文件描述字(file descriptor,fd)是系统中用来唯一记录当前已经打开的文件的标识号,fd是一个整数. 除了file对象外,Python还提供对fd的操作,对fd的操作更加底层,fd和Py ...

  10. 【JAVA、C++】LeetCode 007 Reverse Integer

    Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 解题思路:将数字 ...