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 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 

Tags: none   ( hide tags for unsolved problems )
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 = 0;
 42     char Ch = ' ';
 43     while(!(Ch >= '0' && Ch <= '9')) Ch = getchar();
 44     while(Ch >= '0' && Ch <= '9') {
 45         Ret = Ret*10+Ch-'0';
 46         Ch = getchar();
 47     }
 48     return Ret;
 49 }
 50
 51 const int N = 8, Left[4] = {0, 2, 5, 7}, Right[4] = {1, 3, 4, 6};
 52 int Arr[N];
 53
 54 inline void Input() {
 55     Rep(i, 8) 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 < 4) Tmp = 1;
 71     else if(!Ed) Tmp = 4;
 72     else if(St > 3) Tmp = 5;
 73     else Tmp = 0;
 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 = 0, b = 0;
 82     Rep(i, 4) a += Arr[Left[i]], b += Arr[Right[i]];
 83     if(a != b) puts("IMPOSSIBLE");
 84     else {
 85         Rep(i, 4)
 86             if(Left[i]) Move(Left[i], 0);
 87         Rep(i, 4)
 88             if(Right[i] != 4) Move(Right[i], 4);
 89         while(Arr[0]) Destroy(0, 4);
 90     }
 91 }
 92
 93 int main() {
 94     #ifndef ONLINE_JUDGE
 95     SetIO("F");
 96     #endif
 97     Input();
 98     Solve();
 99     return 0;
100 }

View Code

转载于:https://www.cnblogs.com/StupidBoy/p/4902963.html

ural 1155. Troubleduons相关推荐

  1. Ural 1018 (树形DP+背包+优化)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17662 题目大意:树枝上间连接着一坨坨苹果(不要在意'坨'),给 ...

  2. bzoj1814 Ural 1519 Formula 1(插头dp模板题)

    1814: Ural 1519 Formula 1 Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 924  Solved: 351 [Submit][S ...

  3. PAT甲级1155 Heap Paths (30 分):[C++题解]堆、堆的遍历、树的遍历、dfs输出路径、完全二叉树建树

    文章目录 题目分析 题目链接 题目分析 来源:acwing 分析: 堆首先是完全二叉树,所以先建完全二叉树,由于给定的是层序遍历的数据,所以直接用数组即可,注意数组下标从1开始,这样便满足结点u和左儿 ...

  4. URAL 1635 Mnemonics and Palindromes

    URAL 1635 思路:区间dp+贪心,先n^2处理出每段区间是否是回文串,然后贪心地找每一段1到i的最少分割. 代码: #include<bits/stdc++.h> using na ...

  5. [代码]ural 1655 Somali Pirates

    Abstract ural 1655 Somali Pirates dp Source http://acm.timus.ru/problem.aspx?space=1&num=1655 So ...

  6. ural 1306. Sequence Median(优先级队列 priority_queue用法)

    最近做的ural的题目总是各种错,看了解题报告都是自己没学过的玩意,有点受打击,不过ural的题目质量还是挺好的,多被虐虐有益健康. 这一题要是用数组直接超内存,用优先级队列做,刚接触这个,学习一下优 ...

  7. 1155: 零起点学算法62——输出矩阵

    1155: 零起点学算法62--输出矩阵 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lld Submitted: 997   ...

  8. DFS水题 URAL 1152 False Mirrors

    题目传送门 1 /* 2 题意:一个圈,每个点有怪兽,每一次射击能消灭它左右和自己,剩余的每只怪兽攻击 3 搜索水题:sum记录剩余的攻击总和,tot记录承受的伤害,当伤害超过ans时,结束,算是剪枝 ...

  9. 【BZOJ1814】Ural 1519 Formula 1 插头DP

    [BZOJ1814]Ural 1519 Formula 1 题意:一个 m * n 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数.(n,m<=12) 题解:插头DP板子题,刷板 ...

最新文章

  1. 使用【python语言】和【typescript】进行冒泡排序
  2. K8S集群搭建:安装kubeadm集群部署工具
  3. 2019第十届蓝桥杯C/C++ A组省赛 —— 第四题:迷宫
  4. c++ 走向高级之日积月累
  5. CNI portmap插件实现源码分析
  6. 刘强东宣布向瑞士捐赠160万只口罩及其他大量急需医疗物资
  7. 风投的钱都从哪里来?
  8. 《流畅的Python》读书笔记——接口:从协议到抽象基类
  9. 读懂hadoop、hbase、hive、spark分布式系统架构
  10. 独立站电商广告和营销洞察
  11. 韦东山freeRTOS系列教程之【第六章】信号量(semaphore)
  12. 使用 MQL5 绘制阻力和支撑级别
  13. 3dmax打开错误html,Windows安装3dmax软件失败提示错误三种解决办法
  14. 全球移动通信系统GSM
  15. SQL Server 2008 Express 安装配置详细教程(附详细截图)
  16. 伯禹 动手学深度学习 打卡08 之 深度卷积神经网络(AlexNet)
  17. Joplin+坚果云同步
  18. 跨考计算机—努力换青春无悔(纪录篇)
  19. NodeMCU(ESP8266)使用HTTP Get和Post
  20. Java获取上周一周末和上月初月末

热门文章

  1. S5PV210 | 裸机汇编LED流水灯实验
  2. MMC、CE-ATA、SD、TF、SDIO的异同
  3. Camtasia 2022最新免费版更新新增功能测评
  4. python百钱买百鸡代码_python解决百钱买百鸡
  5. MonkeyScript
  6. C# 获取鼠标选中的文字(屏幕取词)
  7. 简单的切换代码 附控制多个切换方法
  8. html右侧悬浮侧边栏,jQuery页面侧边固定悬浮导航代码(带关闭按钮)
  9. 在Ubuntu系统上在线下载/删除/查看软件包信息apt命令
  10. 21:最大质因子序列