Codeforces 376A. Night at the Museum
1 second
256 megabytes
standard input
standard output
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
zeus
18
map
35
ares
34
To print the string from the first sample it would be optimal to perform the following sequence of rotations:
- from 'a' to 'z' (1 rotation counterclockwise),
- from 'z' to 'e' (5 clockwise rotations),
- from 'e' to 'u' (10 rotations counterclockwise),
- from 'u' to 's' (2 counterclockwise rotations).
In total, 1 + 5 + 10 + 2 = 18 rotations are required.
/*
一个字母盘初始位置在a,问你最少转动多少次,能将给定字的字符串转出来。(每次转动只能转动到相邻字母) 简单的模拟,每次转动只要讨论是正着还是反着转就行了
*/
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<vector>
#include<map>
#include<set>
using namespace std;
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
char str[];
scanf("%s",&str);
int ans=;
ans+=min(str[]-'a','z'+-str[]);
//cout<<ans<<endl;
for(int i=;i<strlen(str);i++)
{
int s1=abs(str[i]-str[i-]);
int s2=min(str[i],str[i-]);
int s3=max(str[i],str[i-]);
ans+=min(s1,('z'-s3)+(s2-'a'+));
//cout<<abs(str[i]-str[i-1])<<" "<<('z'-str[i-1])+(str[i]-'a'+1)<<endl;
//cout<<min(abs(str[i]-str[i-1]),('z'-str[i-1])+(str[i]-'a'+1))<<endl;
}
printf("%d\n",ans);
return ;
}
Codeforces 376A. Night at the Museum的更多相关文章
- codeforces 598D Igor In the Museum
题目链接:http://codeforces.com/problemset/problem/598/D 题目分类:dfs 题目分析:处理的时候一次处理一片而不是一个,不然会超时 代码: #includ ...
- CodeForces 731A Night at the Museum
A. Night at the Museum time limit per test 1 second memory limit per test 256 megabytes input standa ...
- CodeForces 731A Night at the Museum (水题)
题意:给定一个含26个英语字母的转盘,问你要得到目标字符串,至少要转多少次. 析:分别从顺时针和逆时针进行,取最小的即可. #pragma comment(linker, "/STACK:1 ...
- Educational Codeforces Round 1 D. Igor In the Museum bfs 并查集
D. Igor In the Museum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598 ...
- Codeforces Round #376 (Div. 2) A. Night at the Museum —— 循环轴
题目链接: http://codeforces.com/contest/731/problem/A A. Night at the Museum time limit per test 1 secon ...
- Codeforces Round #376A (div2)
Night at the Museum 题意: 有一个转盘,26个英文字母均匀分布在转盘边缘,转针初始位置在字母a,每次只能转动到相邻的字母,然后输入一个由26个字母组成的字符串(最长100),不复位 ...
- Educational Codeforces Round 1(D. Igor In the Museum) (BFS+离线访问)
题目链接:http://codeforces.com/problemset/problem/598/D 题意是 给你一张行为n宽为m的图 k个询问点 ,求每个寻问点所在的封闭的一个上下左右连接的块所能 ...
- 【87.65%】【codeforces 731A】Night at the Museum
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【CodeForces - 598D】Igor In the Museum(bfs)
Igor In the Museum Descriptions 给你一个n*m的方格图表示一个博物馆的分布图.每个方格上用'*'表示墙,用'.'表示空位.每一个空格和相邻的墙之间都有一幅画.(相邻指的 ...
随机推荐
- [AHOI2004]奇怪的字符串
[AHOI2004]奇怪的字符串 题目描述 输入输出格式 输入格式: 输入文件中包含两个字符串X和Y.当中两字符串非0即1.序列长度均小于9999. 输出格式: X和Y的最长公共子序列长度. 输入输出 ...
- 【转】开源中国上看到的一个vim的自动配置的好东西,分享下
https://www.oschina.net/p/onekey-to-vim-ide 变量有高亮,竖行上有直线定位,对python的支持效果更佳,从事C/C++开发的程序员使用也不错.
- Codevs1380没有上司的舞会_KEY
没有上司的舞会 1380 没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description Ural大学有N个职员,编号为1~N.他们有从属关系,也就是说他们的关系 ...
- 对redux的理解
redux原理 某公司有物流(actionType).电商(actionType).广告(actionType)3块业务,在公司财务系统(state)统一记录着三块业务分别赚取到的资金.某天,电商业 ...
- Qt中的坐标系统
Qt使用统一的坐标系统来定位窗口部件的位置和大小. 以屏幕的左上角为原点即(0, 0)点,从左向右为x轴正向,从上向下为y轴正向,这整个屏幕的坐标系统就用来定位顶层窗口: 此外,窗口内部也有自己的坐标 ...
- 关于form表单或者Ajax向后台发送数据时,数据格式的探究
最近在做一个资产管理系统项目,其中有一个部分是客户端向服务端发送采集到的数据的,服务端是Django写的,客户端需要用rrequests模块模拟发送请求 假设发送的数据是这样的: data = {'s ...
- 【转】FTP主动模式和被动模式的比较
总是记不住FTP主动和被动模式的区别.放在这里,以备日后查阅. FTP是仅基于TCP的服务,不支持UDP.与众不同的是FTP使用2个端口,一个数据端口和一个命令端口(也可叫做控制端口).通常来说这 ...
- Promise 对象
Promise 对象用于处理异步请求,保存一个异步操作最终完成(或失败)的结果 语法 new Promise( /* executor */ function(resolve, reject) {.. ...
- JS判断浏览器类型与版本
在JS中判断浏览器的类型,估计是每个编辑过页面的开发人员都遇到过的问题.在众多的浏览器产品中,IE.Firefox.Opera.Safari........众多品牌却标准不一,因此时常需要根据不同的浏 ...
- springboot scheduled并发配置
本文介绍如何使用springboot的sheduled实现任务的定时调度,并将调度的任务实现为并发的方式. 1.定时调度配置scheduled 1)注册定时任务 package com.xiaoju. ...