Codeforces712B【= =】

题意:
题意:
最少需要几步改变能够使得按照原序列的走法从起源走到起源;
思路:
长度奇数肯定不行
偶数的情况下。。
其实题意转变就是有4个数a,b,c,d,在最小的改变下,使a==b,c==d;
那么就是很明显的两两相差除以2就是答案;

#include <bits/stdc++.h>
using namespace std;
typedef __int64 LL;

const int N=1e5+10;
char s[N];

int main()
{
    int len;
    scanf("%s",s);
    len=strlen(s);
    if(len%2)
    {
        puts("-1");
        return 0;
    }
    int L,R,U,D;
    L=R=U=D=0;
    for(int i=0;i<len;i++)
    {
        if(s[i]=='L')
            L++;
        if(s[i]=='R')
            R++;
        if(s[i]=='U')
            U++;
        if(s[i]=='D')
            D++;
    }
    printf("%d\n",(abs(L-R)+abs(U-D))>>1);
    return 0;
}
posted @ 2016-09-14 08:52  see_you_later  阅读(136)  评论(0编辑  收藏  举报