Codeforces Testing Round #16 C.Skier

题意: 一个人在雪地上滑雪,每次可以向上下左右四个方向移动一个单位,如果这条路径没有被访问过,则需要5秒的时间,如果被访问过,则需要1秒(注意:判断的是两点之间的距离,不是单纯的点).给你他的行动轨迹,求消耗的时间.
题解:我们用两个pair来维护边,用map来对边进行标记,每次更新map记得双向更新即可(e.g:(1,2)和(2,1)两个方向都要标记).
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef pair<PII,PII> PP; int t;
string s;
int cnt;
PII o,p;
PP S1,S2;
map<PP,bool> mp; int main() {
ios::sync_with_stdio(false);
cin>>t;
while(t--){
p=o={0,0};
cnt=0;
cin>>s;
mp.clear();
for(char c:s){
if(c=='N') p.se++;
else if(c=='S') p.se--;
else if(c=='W') p.fi--;
else if(c=='E') p.fi++;
S1={o,p};
S2={p,o};
if(mp[S1]) cnt++;
else{
cnt+=5;
mp[S1]=mp[S2]=true;
}
o=p;
}
printf("%d\n",cnt);
}
return 0;
}
Codeforces Testing Round #16 C.Skier的更多相关文章
- Codeforces Beta Round #16 (Div. 2 Only)
Codeforces Beta Round #16 (Div. 2 Only) http://codeforces.com/contest/16 A 水题 #include<bits/stdc+ ...
- Codeforces Beta Round #16 E. Fish (状压dp)(概率dp)
Codeforces Beta Round #16 (Div. 2 Only) E. Fish 题目链接:## 点击打开链接 题意: 有 \(n\) 条鱼,每两条鱼相遇都会有其中一只吃掉对方,现在给你 ...
- Testing Round #16 (Unrated)
比赛链接:https://codeforces.com/contest/1351 A - A+B (Trial Problem) #include <bits/stdc++.h> usin ...
- Codeforces Testing Round #8 B. Sheldon and Ice Pieces 水题
题目链接:http://codeforces.com/problemset/problem/328/B 水题~ #include <cstdio> #include <cstdlib ...
- Codeforces Testing Round #12 C. Subsequences 树状数组维护DP
C. Subsequences Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Testing Round #12 B. Restaurant 贪心
B. Restaurant Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/problem ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Beta Round #16 div 2 C.Monitor最大公约数
C. Monitor time limit per test 0.5 second memory limit per test 64 megabytes input standard input ou ...
- Codeforces Testing Round 14
A:The Way to Home link:http://codeforces.com/contest/910/problem/A 题面:有每次最大跳跃距离d,只有一部分的点可以落脚,求最少几步达到 ...
随机推荐
- 【Spring】IoC概述
Spring框架的核心概念--IoC IoC IoC是Inversion of Control的简写,翻译成汉语就是"控制反转".IoC并不是一门技术,而是一种设计思想,在Spri ...
- Windows系统使用运行框运行程序
配置步骤 1. 在非系统盘创建一个新文件夹,自定义名称.将需要使用运行框启动的程序或文件放入文件夹,并将其更改为自己容易记忆的名称 2. 创建环境变量 右击 "此电脑" → &qu ...
- 原生ajax分享
最近被大佬问了一个很有趣的问题,你还能手打出一个ajax吗?,我当时的想法是有现成的为什么要自己打,后来我反思了一下(只有靠自己才是强者),在这里给大家分享一个我自己打的ajax,也是自己的一个知识点 ...
- 浅谈java中线程和操作系统线程
在聊线程之前,我们先了解一下操作系统线程的发展历程,在最初的时候,操作系统没有进程线程一说,执行程序都是串行方式执行,就像一个队列一样,先执行完排在前面的,再去执行后面的程序,这样的话很多程序的响应就 ...
- Failed to start LSB: starts php-fpm
跟nginx一样都是进程占用,记录下 [root@localhost pazzn]# systemctl status php-fpm.service ● php-fpm-72.service - L ...
- SQL Server 邮箱告警配置
目录 配置数据库邮件 * 手动启用数据库邮件功能 * 配置数据库邮件 * 测试数据库邮件 实现 JOB 任务运行状态的检测 * 定义操作员 * 新建死锁警报 * 设置 SQL Server 代理 创建 ...
- Dubbo 最基本的几个需求
需求 http://dubbo.apache.org/zh-cn/docs/user/preface/requirements.html 在大规模服务化之前,应用可能只是通过 RMI 或 Hessia ...
- Simple decorator that intercepts connection errors and ignores these if settings specify this.
django-redis/cache.py at master · jazzband/django-redis https://github.com/jazzband/django-redis/blo ...
- 逃逸分析与栈、堆分配分析 escape_analysis
小结: 1.当形参为 interface 类型时,在编译阶段编译器无法确定其具体的类型.因此会产生逃逸,最终分配到堆上. 2.The construction of a value doesn't d ...
- cnpm安装依赖时报Error: Cannot find module 'core-js/modules/es6.regexp.constructor'
解决方案:npm install core-js@2 大致猜测:cnpm掉包所致...