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的应用)相关推荐

  1. Testing Round #16 (Unrated)

    B. Square? 题目链接:https://codeforces.ml/contest/1351/problem/B #include <bits/stdc++.h>#define r ...

  2. Codeforces Testing Round #16 (Unrated)C (集合)

    链接 题意 思路 代码 #include<bits/stdc++.h> using namespace std; const int N = 2e5 + 10; set<pair&l ...

  3. Codeforces Testing Round #14 (Unrated) C. Minimum Sum

    给你仅含有字符'a'~'j'的字符串,让你用字符'0'~'9'替换其中的字符,使得替换后所有字符串代表的整数之和最小,假设字符串并不会出现前导零. 数据规模:n(1<n<1000)个字符串 ...

  4. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  5. Educational Codeforces Round 16 C. Magic Odd Square 矩阵构造

    传送门 文章目录 题意: 思路: 题意: 给你一个奇数nnn,让你构造一个n∗nn*nn∗n的矩阵,矩阵的每个位置依次填上[1,n∗n]之内的数[1,n*n]之内的数[1,n∗n]之内的数,满足每行. ...

  6. 吴昊品游戏核心算法 Round 16 —— 吴昊教你玩口袋妖怪 第四弹 拉帝亚斯?!拉帝欧斯?!...

    作为讲述口袋妖怪的Round 16,这里,我会采用"夹叙夹议,夹议夹叙"的模式进行编排.也就是在议论一些口袋妖怪中的小游戏的核心算法的同时,叙述一下我对口袋妖怪的理解以及我与这一系 ...

  7. 吴昊品游戏核心算法 Round 16 ——吴昊教你玩口袋妖怪 第三弹 地洞谜题

    这样的场景我们应该经常遇到的吧,哈哈! 口袋妖怪的地洞要算是最令人讨厌的了,因为,有些地洞是全黑的,你即使用了闪光灯(必选道具#03),你有时也只能用GBA外壳的荧光屏作为道具才能将整个地洞看清楚. ...

  8. 吴昊品游戏核心算法 Round 16 —— 吴昊教你玩口袋妖怪 第九弹 冰系道馆

    道馆之战!!!这一次,道馆由电系变为了冰系,和龙系的道馆不一样,冰系的道馆有冰系的规定.如图所示,一共有三层,上面一层总是比下面一层要复杂一些.在冰系道馆中,有如下的两个规则:(1)我们不会在冰面上划 ...

  9. 吴昊品游戏核心算法 Round 16 —— 吴昊教你玩口袋妖怪 第六弹 龙系道馆

    道馆之战!!!如图所示,此乃口袋妖怪的道馆战中的龙系道馆,一般情况下,在每一个系列的口袋妖怪中,龙系道馆往往是排列在最后的,我们通过一些滑动可以到达我们所想到达的地方(冰块并不会因此而破碎).但是,我 ...

最新文章

  1. 特征工程(一)countvectororizer
  2. mysql 读写分离中间层
  3. Java学习笔记(1)——基本数据类型
  4. 将服务器置于最终用户附近可解决性能问题?—Vecloud微云
  5. 函数幂计算机中怎么用,Excel中幂函数的操作使用
  6. 富交互Web应用中的撤销和前进
  7. Android Binder设计与实现 - 实现篇(1)
  8. EV3 直接命令 - 第一课 无为的艺术
  9. SQL Server 2008下日志清理方法
  10. android适配规则(一)
  11. 虚拟服务器配置推荐,如何选择虚拟主机配置
  12. 单片机矩阵键盘c语言程序,stc89c52单片机下的矩阵键盘程序
  13. si4463跳频功能简介
  14. C语言交换两个变量数值的几种方法
  15. Macbook reset PRAM
  16. 如何将计算机的硬盘分割,电脑硬盘如何快速分区
  17. 微信小程序开发之——婚礼邀请函-项目展示(4.1)
  18. confluence 空间复制
  19. python excel模板_如何利用Excel与Python制作PPT
  20. golang语言 []interface{}和interface{}

热门文章

  1. 量子计算机 模拟,新量子算法将量子模拟器变成量子计算机,可以进行量子计算...
  2. python爬虫天气数据_python爬虫:天气数据的分析
  3. Android开发之自定义view绘制坐标位置出错的问题解决
  4. java给定任意_java生成任意整数随机数(任意指定范围)
  5. oracle数据库的诊断目标位置,刚安装的数据库卸载 指定数据库的诊断目标位置不存在...
  6. 想问一下C++里queue要怎么遍历
  7. 前端学PHP之面向对象系列第六篇——简单图形面积计算器实现
  8. eclipse插件安装,万能方法
  9. 成为一名JAVA高级工程师你需要学什么
  10. 【Boost】系列02:内存管理之scoped_ptr智能指针