UVa 10618 跳舞机
https://vjudge.net/problem/UVA-10618
这道题目题意很复杂,代码也是参考了别人的,因为自己实在是写不出。d[i][a][b][s]表示分析到第i个箭头时,此时左脚处于a,右脚处于b,上次移动的脚为s时的最小能量消耗。
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std; #define INF 10000000 char str[];
int len;
int d[][][][];
int action[][][][];
int pos[];
char place[] = ".LR"; int energy(int a, int ta)
{
if (a == ta) return ; //该脚没有移动
if (a + ta == ) return ; //该脚移动到相对箭头
return ; //该脚移动到相邻箭头
} int energy(int a, int b, int s, int f, int t, int& ta, int& tb)
{
ta = a;
tb = b;
//移动之后的脚的位置
if (f == ) //左脚
ta = t;
if (f == ) //右脚
tb = t; if (ta == tb) return -; //移动之后两只脚在同一位置
if (ta == && tb == ) return -; //背向跳舞机状态
if (a == && tb != b) return -; //左脚在右箭头时,不能移动右脚
if (b == && ta != a) return -; //右脚在左箭头时,不能移动左脚 int e = ;
if (f == ) //没有移动
e = ;
else if (f != s) //和上个周期移动的脚不同
e = ;
else
{
if (f == )
e = energy(a, ta);
else
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(a, b, s, f, t, ta, tb);
if (e < ) return;
//逆推
int cost = d[i + ][ta][tb][f] + e;
int& ans = d[i][a][b][s];
if (ans>cost)
{
ans = cost;
action[i][a][b][s] = f * + t;
}
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
pos['U'] = ;
pos['D'] = ;
pos['L'] = ;
pos['R'] = ;
while (cin >> str)
{
if (str[] == '#') break;
len = strlen(str);
memset(d, , sizeof(d)); //逆推导
for (int i = len - ; i >= ; i--)
{
for (int a = ; a < ; a++)
for (int b = ; b < ; b++)
{
//两只脚不可能在同一箭头上
if (a == b) continue;
for (int s = ; s < ; s++)
{
d[i][a][b][s] = INF;
if (str[i] == '.')
{
//不移动
update(i, a, b, s, , );
//任意往4个位置移动
for (int t = ; t < ; t++)
{
update(i, a, b, s, , t);
update(i, a, b, s, , t);
}
}
else
{
update(i, a, b, s, , pos[str[i]]); //左脚移动到指定位置
update(i, a, b, s, , pos[str[i]]); //右脚移动到指定位置
}
}
}
}
//初始时左脚在左箭头,右脚在右箭头
int a = , b = , s = ;
for (int i = ; i < len; i++)
{
int f = action[i][a][b][s] / ;
int t = action[i][a][b][s] % ;
cout << place[f];
s = f;
if (f == )
a = t;
else if (f == )
b = t;
}
cout << endl;
}
}
UVa 10618 跳舞机的更多相关文章
- 【暑假】[深入动态规划]UVa 10618 Fun Game
UVa 10618 Fun Game 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=36035 思路: 一圈人围坐 ...
- 【暑假】[深入动态规划]UVa 10618 Fixing the Great Wall
UVa 10618 Fixing the Great Wall 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=361 ...
- 【暑假】[深入动态规划]UVa 10618 Tango Tango Insurrection
UVa 10618 Tango Tango Insurrection 题目: Problem A: Tango Tango Insurrection You are attempting to lea ...
- UVA 10618 Tango Tango Insurrection
https://vjudge.net/problem/UVA-10618 题目 你想学着玩跳舞机.跳舞机的踏板上有4个箭头:上.下.左.右.当舞曲开始时,屏幕上会有一些箭头往上移动.当向上移动箭头与顶 ...
- uva 10618 Tango Tango Insurrection 解题报告
Tango Tango Insurrection Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebu ...
- 【Uva 10618】Tango Tango Insurrection
[Link]: [Description] 玩跳舞机. 有一定的约束. 归纳起来就是以下三点 1.两只脚不能同时踩一个位置 2.如果左脚踩在了右键上,那么下一次移动的一定要是左脚 3.如果右脚踩在了左 ...
- 【暑假】[深入动态规划]UVa 10618 The Bookcase
UVa 12099 The Bookcase 题目: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=42067 思路: ...
- uva 1291(dp)
题意:有一台跳舞机,中间是0.上左下右分别代表1 2 3 4,初始状态人站在中间.两仅仅脚都踏在0上,然后给出一段序列以0为结束,要按顺序踩出来,从0踏到四个方向须要消耗2点能量,从一个方向到相邻的方 ...
- UVA 1291 Dance Dance Revolution(DP)
意甲冠军:跳舞机有一个上5积分,分别central, top, bottom, left, right分,区区足站立还是需要1点物理,从一个单纯的脚central点上须要2点体力,从一个点上移动到相邻 ...
随机推荐
- vertx异步编程测试
vertx是异步编程的框架,性能较高,开发简单.异步编程就是当一个请求来了,vertx将其交由一个事件进行处理,然后继续向下执行,等处理完成,返回结果,通知客户端.这是一个由服务端反向调用客户端的过程 ...
- HTTP权威指南读书笔记
HTTP权威指南笔记 读书有两种境界,第一种境界是将书读薄,另一种是读厚.本篇文章就是HTTP权威指南的读书笔记,算是读书的第一重境界,将厚书读薄.文章对HTTP的一些关键概念做了比较详细的概述,通读 ...
- 跟我学Makefile(七)
定义模式规则 使用模式规则来定义一个隐含规则.一个模式规则就好像一个一般的规则,只是在规则中,目标的定义需要有“%”字符.“%”的意思是表示一个或多个任意字符.在依赖目标中同样可以使用“%”,只是依赖 ...
- Python 使用ctypes调用 C 函数
在python中通过ctypes可以直接调用c的函数,非常简单易用 下面就一步一步解释用法吧,以Linux为例讲解. 1, 首先确定你的python支持不支持ctypes python2.7以后cty ...
- 【Cocos2dx 3.3 Lua】导出Cocos2dx API文档
一.Doxygen导出Cocos2dx html doc 1.1 打开Doxygen软件,选择 File-->Open打开Cocos2dx docs目录下的doxyge ...
- Selenium Webdriver——操作隐藏的元素(三)switchTo().frame()
在web 应用中经常会遇到frame 嵌套页面的应用,页WebDriver 每次只能在一个页面上识别元素,对于frame 嵌套内的页面上的元素,直接定位是定位是定位不到的.这个时候就需要通过switc ...
- Ajax棵
ajax 1.什么是ajax?(异步请求,局部刷新) ajax是一个改善用户体验的技术,实质上是利用浏览器端ajax对象()向服务器发送异步(ajax对象在向服务器发送请求的时候,用户可以继续其他操作 ...
- !! A股历史平均市盈率走势图
http://value500.com/PE.asp 一. A股历史平均市盈率走势图 *数据来源:上海证券交易所 分享到: 354 - 上海A股 深圳A股更新时间 2017年6月7日 2017年6月7 ...
- js数组中indesOf方法的使用
<html> <head> <title>数组的操作</title> <script type="text/javascript&quo ...
- mysql服务器上的mysql这个实例中表的介绍
1.user表. 分个分隔符