ural 1155. Troubleduons

时间:2021-01-07 21:44:31

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.
ural 1155. 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 0 1 0 3 1 0 0 
EF-
EA-
AD+
AE-
DC-
0 1 0 1 2 3 2 2
IMPOSSIBLE
Problem Source: Ural Collegiate Programming Contest, April 2001, Perm, English Round 
Difficulty: 468
 
题意:一个正方体,八个顶点各有一些颗粒在上面,每次相邻的两个点可以同时增加或消去一个颗粒,问让你给出一个操作序列把全部颗粒消去。
分析:显然,肯定先消去相邻的,知道不能消去为止。
按照这个思路,最后是要把点先增加再消去
我们发现互不相邻的点上的颗粒可以通过先增加,再消去的操作移动
比如a,0,c  ->  a+c, c, c -> a, 0, 0
就是这样。。。。
然后题目并没有要求最短操作序列。。。
所以我们把颗粒全都移到相邻的两个点上再消去就好。
 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name) {
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint() {
int Ret = ;
char Ch = ' ';
while(!(Ch >= '' && Ch <= '')) Ch = getchar();
while(Ch >= '' && Ch <= '') {
Ret = Ret*+Ch-'';
Ch = getchar();
}
return Ret;
} const int N = , Left[] = {, , , }, Right[] = {, , , };
int Arr[N]; inline void Input() {
Rep(i, ) scanf("%d", Arr+i);
} inline void Create(int x, int y) {
Arr[x]++, Arr[y]++;
printf("%c%c+\n", 'A'+x, 'A'+y);
} inline void Destroy(int x, int y) {
Arr[x]--, Arr[y]--;
printf("%c%c-\n", 'A'+x, 'A'+y);
} inline void Move(int St, int Ed) {
int Tmp;
if(!Ed && St < ) Tmp = ;
else if(!Ed) Tmp = ;
else if(St > ) Tmp = ;
else Tmp = ;
while(Arr[St]) {
if(!Arr[Tmp]) Create(Tmp, Ed);
Destroy(Tmp, St);
}
} inline void Solve() {
int a = , b = ;
Rep(i, ) a += Arr[Left[i]], b += Arr[Right[i]];
if(a != b) puts("IMPOSSIBLE");
else {
Rep(i, )
if(Left[i]) Move(Left[i], );
Rep(i, )
if(Right[i] != ) Move(Right[i], );
while(Arr[]) Destroy(, );
}
} int main() {
#ifndef ONLINE_JUDGE
SetIO("F");
#endif
Input();
Solve();
return ;
}