5.21每日一题题解

Skier

涉及知识点:

  • 思维

solution:

  • \(我们只需要考虑这个人到这个点所经过的路径是否是滑过的,而不能只判断这个人到的点\)
  • \(由此,我们可以使用map,来判断每个点四周是否已经滑过来代替判断判断路径\)
  • \(多说一句,为什么只判断这个点不行\)
  • \(因为这个人可从另一个方向到这个点,例子EEENNNEEESSSWWW,正解应是75\)

std:

#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 08:39  QFNU-ACM  阅读(85)  评论(0编辑  收藏  举报