UVA10618TangoTangoInsurrection
来源:互联网 发布:c语言中char的意思 编辑:程序博客网 时间:2024/05/17 08:35
//UVA10618TangoTangoInsurrection #include<cstdio>#include<cstring>const int MAXN = 70 + 5;int pos[256];char seq[MAXN];const int up = 0, down = 3, right = 2, left = 1;const char operation[] = ".LR";int action[MAXN][4][4][3], d[MAXN][4][4][3];int energy(int a, int ta) {if(a == ta) return 3;else if(a + ta == 3) return 7;return 5;}int energy(int i, int a, int b, int s, int f, int t, int& ta, int& tb) {ta = a; tb = b;if(f == 0) return 0;if(f == 1) ta = t;else if(f == 2) tb = t;if(ta == tb) return -1;if(ta == right && tb == left) return -1;if(ta == right && tb != b) return -1;if(tb == left && ta != a) return -1;int e;if(f != s) e = 1;else if(f == 1) e = energy(a, ta);else if(f == 2) e = energy(b, tb);return e;}void update(int i, int a, int b, int s, int f, int t) {int ta, tb; int e = energy(i, a, b, s, f, t, ta, tb);if(e < 0) return ;//非法的移动方案 int& ans = d[i][a][b][s];int cost = d[i + 1][ta][tb][f] + e;if(cost < ans) {ans = cost;action[i][a][b][s] = f * 4 + t;//编码本次移动方案 } } int main() { pos['U'] = 0; pos['D'] = 3; pos['L'] = 1; pos['R'] = 2;while(scanf("%s", seq) == 1) {memset(d, 0, sizeof(d));if(seq[0] == '#') break;int n = strlen(seq);for(int i = n - 1; i >= 0; i--) for(int a = 0; a < 4; a++) for(int b = 0; b < 4; b++) if(a != b) for(int s = 0; s < 3; s++) { d[i][a][b][s] = 10 * n; if(seq[i] == '.') { update(i, a, b, s, 0, 0);//不动 for(int t = 0; t < 4; t++) { update(i, a, b, s, 1, t);//动左脚到位置t update(i, a, b, s, 2, t);//动右脚到位置t }}else {update(i, a, b, s, 1, pos[seq[i]]);update(i, a, b, s, 2, pos[seq[i]]); }} int a = left, b = right, s = 0; for(int i = 0; i < n; i++) { int t = action[i][a][b][s] % 4; int f = action[i][a][b][s] / 4; printf("%c", operation[f]); s = f; if(f == 1) a = t;//本步移动的是左脚,下同理 else if(f == 2) b = t;}printf("\n");} return 0;}/**/
阅读全文
0 0
- UVA10618TangoTangoInsurrection
- POJ
- 浅谈深度学习尝常识:泛化、过拟合、Dropout、Attention
- 第三章 第二节:修改数据表——ALTER(三) 删除约束
- HDU5444 Elven Postman(搜索二叉树模板)
- Spring—Quartz定时调度CronTrigger时间配置格式说明与实例
- UVA10618TangoTangoInsurrection
- 继承的限制
- springboot【15】缓存之EhCache
- TCP建立连接为什么需要三次握手
- springBoot基础系列--properties配置
- Jquery Ajax请求WebApi(Post请求方式)
- HDU 4686 Arc of Dream(构造矩阵 快速幂)
- Python读取txt内容写入xlsx格式的excel中
- Android 检测内存泄漏