2019/12/12 CF-1272-B Snow Walking Robot

Codeforces Round #605 (Div. 3)

2019/12/12 CF-1272-B Snow Walking Robot_第1张图片

题目链接:http://codeforces.com/contest/1272/problem/B

题意大意:

       尽可能少的删除无效或多余指令,并重新排列指令使机器人从原点出发,最后回到原点,中间不能经过同一个点两次(原点也仅能出发和结束经过)。

测试样例:

input
6
LRU
DURLDRUDRULRDURDDL
LRUDDLRUDRUL
LLLLRRRR
URDUR
LLL

output
2
LR
14
RUURDDDDLLLUUR
12
ULDDDRRRUULL
2
LR
2
UD
0

Note

There are only two possible answers in the first test case: "LR" and "RL".

The picture corresponding to the second test case:

 

2019/12/12 CF-1272-B Snow Walking Robot_第2张图片

Note that the direction of traverse does not matter

Another correct answer to the third test case: "URDDLLLUURDR".

AC代码:

#include
using namespace std;
const int maxn=1e5+5;
char s[maxn];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",s);
        int len=strlen(s);
        int cnt[4];
        memset(cnt,0,sizeof(cnt));
        for(int i=0;i

 

你可能感兴趣的:(题集)