uva 10618 Tango Tango Insurrection 解题报告
| Time Limit: 3000MS | 64bit IO Format: %lld & %llu |
You are attempting to learn to play a simple arcade dancing game. The
game has 4 arrows set into a pad: Up, Left, Down, Right. While a song
plays, you watch arrows rise on a screen, and when they hit the top, you
have to hit the corresponding arrows on the pad. There is no penalty for
stepping on an arrow without need, but note that merely standing on an
arrow does not activate it; you must actually tap it with your foot. Many
sequences in the game are very fast-paced, and require proper footwork
if you don’t want to tire yourself out. Write a program to determine the
easiest way to execute a certain sequence of arrows.
We will work with a basic time unit of an eighth-note. At any given time, your left foot and right
foot will each be on distinct arrows. Only one foot may perform an action (changing arrows and/or
tapping) during any time unit; jumping is not allowed. Also, you must remain facing forward in order
to see the screen. This puts limitations on which feet you can use to hit which arrows. Finally, hitting
two arrows in a row with the same foot (“double-tapping”) is exhausting, because you can’t shift your
weight onto that foot. Ideally, you want to alternate feet all the way through a string of consecutive
arrows.
Performing an action with a foot costs 1 unit of energy if it did NOT
perform an action in the previous time unit. If it did, then it costs 3 units
if it doesn’t change arrows, 5 units if it moves to an adjacent arrow, and
7 units if it moves directly across the pad (between Up and Down, or Left
and Right).
Under normal circumstances, you can’t put your left foot on Right, or
your right foot on Left. However, you CAN do a temporary “crossover”:
if your left foot is on Up or Down, you can twist your hips and put your
right foot on Left — but until your right foot moves away, you can’t move
your left to a different arrow. (Imagine the tangle your legs would get into
if you tried!) Similarly, you can cross your left foot over/behind your right.
Input
You will be given multiple arrow sequences to provide foot guides for.
Every sequence consists of a line containing from 1 to 70 characters, representing the arrow that must
be hit at each time unit. The possible characters are ‘U’, ‘L’, ‘D’, and ‘R’, signifying the four arrows, or
a period, indicating that no arrow need be hit. Assume that your left and right feet start on the Left
and Right arrows for the first time unit of a sequence.
There are at most 100 sequences. Input is terminated by a line consisting of a single ‘#’.
Output
For each input sequence, output a string of the same length, indicating which foot should perform an
action at each time step, or ‘.’ if neither does. If there are multiple solutions that require minimal
energy, any will do.
Sample Input
LRLRLLLLRLRLRRRRLLRRLRLDU...D...UUUUDDDD
#
Sample Output
LRLRLLLLRLRLRRRRLLRRLRLRL...R...LLLLRRRR
——————————————————我是分割线————————————————————
DP题目
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<iomanip>
#include<cassert>
#include<climits>
#include<functional>
#include<bitset>
#include<vector>
#include<list>
#define maxn 100001
#define F(i,j,k) for(int i=j;i<=k;i++)
#define M(a,b) memset(a,b,sizeof(a))
#define FF(i,j,k) for(int i=j;i>=k;i--)
#define inf 0x3f3f3f3f
#define maxm 1001
#define mod 998244353
//#define LOCAL
using namespace std;
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
const int LEFT=;
const int RIGHT=;
const int MAXN=;
int n;
int d[MAXN][][][];
char seq[MAXN];
int action[MAXN][][][];
char place[]=".LR";
int pos[];
int energ(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;
else if(f==) tb=t;
if (ta==tb) return -; // 下一个状态猜到同一个位置
if (ta==RIGHT&&tb==LEFT) return -; // 背向跳舞机
if(a==RIGHT&&tb!=b) return -; // a左脚在右脚的位置,但是移动了右脚,无论移动到哪儿,都是不合法的
if(b==LEFT&&ta!=a) return -;
int e=;
if(f==) e=;
else if(f!=s) e=;
else
{
if (f==) e=energ(a,ta);
else e=energ(b,tb);
}
return e;
}
void update(int i,int a,int b,int s,int f,int t)
{
int ta,tb;
int e;
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;
}
}
void solve()
{
n=strlen(seq);
memset(d,,sizeof(d));
for(int i=n-;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]=0x1f1f1f1f;
if (seq[i]=='.')
{
update(i,a,b,s,,);
for(int t=;t<;t++)
{
update(i,a,b,s,,t);
update(i,a,b,s,,t);
}
}
else
{
update(i,a,b,s,,pos[seq[i]]);
update(i,a,b,s,,pos[seq[i]]);
}
}
}
int a=;
int b=;
int s=;
for (int i=;i<n;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;
//cout<<d[0][1][2][0]<<endl;
}
int main()
{
std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y;
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif
pos['U']=;
pos['D']=;
pos['L']=;
pos['R']=;
while(cin>>seq)
{
if (seq[]=='#')
break;
solve();
}
return ;
}
uva 10618 Tango Tango Insurrection 解题报告的更多相关文章
- 【Uva 10618】Tango Tango Insurrection
[Link]: [Description] 玩跳舞机. 有一定的约束. 归纳起来就是以下三点 1.两只脚不能同时踩一个位置 2.如果左脚踩在了右键上,那么下一次移动的一定要是左脚 3.如果右脚踩在了左 ...
- uva 10881 Piotr's Ants 解题报告
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&pa ...
- UVA 12538 Version Controlled IDE 解题报告
题意:给三种操作 1.在p位置插入一个字符串. 2.从p位置开始删除长度为c的字符串 3.输出第v个历史版本中从p位置开始的长度为c的字符串 解法:可以用平衡树做,但是不会.后来又听说可一用一个叫ro ...
- UVa 455 - Periodic Strings - ( C++ ) - 解题报告
1.题目大意 求一个长度不超过80的字符串的最小周期. 2.思路 非常简单,基本就是根据周期的定义做出来的,几乎不需要过脑. 3.应该注意的地方 (1) 最后输出的方式要注意,不然很容易就PE了.不过 ...
- Uva 106 - Fermat vs. Pythagoras 解题报告
数论题,考查了本原勾股数(PPT) 对一个三元组(a,b,c)两两互质 且满足 a2 + b2 = c2 首先有结论 a 和 b 奇偶性不同 c总是奇数(可用反证法证明,不赘述) 设 a为奇数 b为偶 ...
- 【暑假】[深入动态规划]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
[UVa-10618] Tango Tango Insurrection ◇ 题目 +vjudge 链接+ (以下选自<算法竞赛入门经典>-刘汝佳,有删改) <题目描述> 你想 ...
- 2020.6.16 night 解题报告
2020.6.16 night 解题报告 link 标签(空格分隔): 题解 概率与期望 T1 : Crossing Rivers UVA - 12230 SB题. 很唬人的一个连续期望. 很明显,在 ...
- CH Round #56 - 国庆节欢乐赛解题报告
最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...
随机推荐
- USACO 6.4 The Primes
The PrimesIOI'94 In the square below, each row, each column and the two diagonals can be read as a f ...
- Caffe训练AlexNet网络,精度不高或者为0的问题结果
当我们使用Caffe训练AlexNet网络时,会遇到精度一值在低精度(30%左右)升不上去,或者精度总是为0,如下图所示: 出现这种情况,可以尝试使用以下几个方法解决: 1.数据样本量是否太少,最起码 ...
- LoadRunner中的IP欺骗的设置以及误区
LoadRunner中的IP欺骗的设置以及误区 最近在忙着部署web性能测试的环境后,对IP欺骗进行设置,特地做个笔记,给自己的学习历程留下点足迹. 一. 什么是IP欺骗? 做什么事首先要问个为什么, ...
- NHibernate 错误
Unable to locate persister for the entity named 'Model.Customer'.The persister define the persistenc ...
- umount /dev/shm
[root@test ~]# umount /dev/shm umount: /dev/shm: device is busy. (In some cases useful info a ...
- iOS 9应用开发教程之定制应用程序图标以及真机测试
iOS 9应用开发教程之定制应用程序图标以及真机测试 定制ios9应用程序图标 在图1.12中可以看到应用程序的图标是网状白色图像,它是iOS模拟器上的应用程序默认的图标.这个图标是可以进行改变的.以 ...
- Codeforces.809E.Surprise me!(莫比乌斯反演 虚树)
题目链接 \(Description\) 给定一棵树,求\[\frac{1}{n(n-1)/2}\times\sum_{i\in[1,n],j\in[1,n],i\neq j}\varphi(a_i\ ...
- hdu 2216 bfs
题目大意:两个东西朝相同方向移动Sample Input4 4XXXX.Z...XS.XXXX4 4XXXX.Z...X.SXXXX4 4XXXX.ZX..XS.XXXXSample Output11 ...
- 一个.net下的轻量级的Serverless 文档数据库LiteDB
今天发现了一个.net下的轻量级的Serverless 文档数据库LiteDB,感觉还不错 官方网站: http://www.litedb.org/ 项目主页: https://github.com/ ...
- Android 通话记录分析
http://stackoverflow.com/questions/6786666/how-do-i-access-call-log-for-android http://android2011de ...
uDebug