zoukankan      html  css  js  c++  java
  • 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;
    }
    
    
    
  • 相关阅读:
    [NOIP2011] 玛雅游戏
    [bzoj4025] 二分图
    [10.2模拟] tree
    [10.3模拟] color
    [10.2模拟] teach
    [10.2模拟] plan
    [10.2模拟] book
    [bzoj4999] This Problem Is Too Simple!
    [9.28模拟] good
    [bzoj3884] 上帝与集合的正确用法
  • 原文地址:https://www.cnblogs.com/QFNU-ACM/p/12928190.html
Copyright © 2011-2022 走看看