Skier

原题地址

Skier

考察知识点

思维

题意

一个人经过之前没有滑过的路径一次花费5,滑过之前到的地方一次花费1,(每次只划一米),问你他滑完之后需要多长时间

思路

  •  这题要注意判断是否滑过不是判断这个点是否滑过,而是到这个点的路径是否滑过
    
  •  剩下的就是使用map解决了
    

代码

#include<bits/stdc++.h>
using namespace std;
typedef  long long LL;
LL n , m , k;

int main(){
        cin >>n;
        while(n--){
            string s;cin >>s;
            map<pair<LL ,LL> , LL > mp[10];
            LL cnt =0 ;
            int len =s.size();
            int u =0 ,r =0 ;
            for(int i=0;i<len;i++){
                if(s[i]=='N'){
                    u++ ;
                    if(mp[1][{u,r}]||mp[2][{u-1,r}])cnt++;
                    else cnt+=5;
                    mp[1][{u,r}]=1,mp[2][{u-1,r}] =1 ;
                }
                if(s[i]=='S'){
                    u--;
                    if(mp[2][{u,r}]||mp[1][{u+1,r}])cnt++;
                    else cnt+=5;
                    mp[2][{u,r}]=mp[1][{u+1,r}] =1 ;
                }
                if(s[i]=='E'){
                    r--;
                    if(mp[3][{u,r}]||mp[4][{u,r+1}])cnt++;
                    else cnt+=5;
                    mp[3][{u,r}]=mp[4][{u,r+1}] =1 ;
                }
                if(s[i]=='W'){
                    r++;
                    if(mp[4][{u,r}]||mp[3][{u,r-1}])cnt++;
                    else cnt+=5;

                    mp[4][{u,r}]=mp[3][{u,r-1}] =1 ;
                }
//cout<<u<<" "<<r <<endl ;
            }
            cout <<cnt <<endl;
        }
        return 0;
}

posted @ 2020-05-21 07:51  dsrcis  阅读(362)  评论(0编辑  收藏  举报