CodeForces 626A Robot Sequence

枚举一下就好,时间复杂度o(n*n)

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<iostream>
using namespace std;

struct X
{
    int x;
    int y;
}p[200+10];
char s[200+10];
int n;

int main()
{
    scanf("%d",&n);
    scanf("%s",s);
    p[0].x=0;
    p[0].y=0;
    for(int i=0;s[i];i++)
    {
        p[i+1].x=p[i].x;
        p[i+1].y=p[i].y;
        if(s[i]=='U') p[i+1].y++;
        if(s[i]=='D') p[i+1].y--;
        if(s[i]=='L') p[i+1].x--;
        if(s[i]=='R') p[i+1].x++;
    }
    int ans=0;
    for(int i=0;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            if(p[i].x==p[j].x&&p[i].y==p[j].y)
                ans++;
    printf("%d\n",ans);
    return 0;
}

 

posted @ 2016-02-20 16:16  Fighting_Heart  阅读(167)  评论(0编辑  收藏  举报