日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Testing Round #16 (Unrated) C. Skier(map的应用)

發布時間:2023/12/15 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Testing Round #16 (Unrated) C. Skier(map的应用) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

outputstandard output
Skier rides on a snowy field. Its movements can be described by a string of characters ‘S’, ‘N’, ‘W’, ‘E’ (which correspond to 1 meter movement in the south, north, west or east direction respectively).

It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is 5 seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes 1 second.

Find the skier’s time to roll all the path.

Input
The first line contains an integer t (1≤t≤104) — the number of test cases in the input. Then t test cases follow.

Each set is given by one nonempty string of the characters ‘S’, ‘N’, ‘W’, ‘E’. The length of the string does not exceed 105 characters.

The sum of the lengths of t given lines over all test cases in the input does not exceed 105.

Output
For each test case, print the desired path time in seconds.

Example
inputCopy
5
NNN
NS
WWEN
WWEE
NWNWS
outputCopy
15
6
16
12
25
思路:我們判斷這條邊有沒有走過,主要就是看這條邊的兩個點有沒有同時出現過,同時出現過就是走過,否則就沒有。
主要用到了map。
代碼如下:

#include<bits/stdc++.h> #define ll long long using namespace std;string s; map<pair<int,int>,int> mp,mp1; int main() {int t;scanf("%d",&t);while(t--){mp.clear();mp1.clear();cin>>s;int ans=0;int cnt=0;mp[make_pair(0,0)]=++cnt;int x=0,y=0;int pre;for(int i=0;i<s.length();i++){pre=mp[make_pair(x,y)];if(s[i]=='N') x--;else if(s[i]=='S') x++;else if(s[i]=='W') y--;else y++;if(mp[make_pair(x,y)]==0) mp[make_pair(x,y)]=++cnt;int now=mp[make_pair(x,y)];if(mp1[make_pair(pre,now)]==0&&mp1[make_pair(now,pre)]==0) ans+=5;else ans+=1;mp1[make_pair(pre,now)]=mp1[make_pair(now,pre)]=1;}cout<<ans<<endl;}return 0; }

努力加油a啊,(o)/~

總結

以上是生活随笔為你收集整理的Testing Round #16 (Unrated) C. Skier(map的应用)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。