CodeForces-731A
每次找到最短距离,然后更新指针的位置。
AC代码:
#include<cstdio> #include<cmath> const int maxn=100+5; char s[maxn]; int min(int a,int b){ return a<b?a:b; } int main(){ while(scanf("%s",s)!=EOF){ int ans=0; int po=0; for(int i=0;s[i]!='\0';++i){ ans+=min(fabs(s[i]-'a'-po),26-fabs(s[i]-'a'-po)); po=s[i]-'a'; } printf("%d\n",ans); } return 0; }
如有不当之处欢迎指出!
CodeForces-731A的更多相关文章
- 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 ...
- 【87.65%】【codeforces 731A】Night at the Museum
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- Java并发编程的艺术读书笔记(1)-并发编程的挑战
title: Java并发编程的艺术读书笔记(1)-并发编程的挑战 date: 2017-05-03 23:28:45 tags: ['多线程','并发'] categories: 读书笔记 --- ...
- Python中几种数据类型list, tuple,dict,set的使用演示
还是直接上代码,看着代码运行,看函数介绍 # coding=utf-8 # 1 list-列表 的用法 students = [1,2,3] a = 5 classmates = [students* ...
- Newtonsoft.Json 版本冲突时解决方案
如果同一项目中不同第三方类库分别使用了不同版本的Newtonsoft.Json的情况下,可以在主项目配置文件中添加以下节点,将0.0.0.0-11.0.0.0此区间的Newtonsoft.Json使用 ...
- PHP如何读取json数据
1的 <?php $json = '{"a":1,"b":2,"c":3,"d":4,"e": ...
- 【转】CString,string,char*综合比较
(一) 概述 1.string和CString均是字符串模a板类: 2.string为标准模板类(STL)定义的字符串类,已经纳入C++标准之中: 3.CString(typedef CString ...
- Python类的__getitem__和__setitem__特殊方法
class testsetandget: kk = {}; def __getitem__(self, key): return self.kk[key]; ...
- [DeeplearningAI笔记]神经网络与深度学习2.11_2.16神经网络基础(向量化)
觉得有用的话,欢迎一起讨论相互学习~Follow Me 2.11向量化 向量化是消除代码中显示for循环语句的艺术,在训练大数据集时,深度学习算法才变得高效,所以代码运行的非常快十分重要.所以在深度学 ...
- 08_Python编码与解码
一.编码的由来 因为计算机只能处理010101二进制数据,如果要处理文本,图像,视频等,需要我们把数据转换成01010二进制格式才能被计算机处理 最先出现的是ASCII,用8位一个字节来表示,成为单字 ...
- 安装pcntl以实现php多进程
pcntl 扩展包一般就在php源码的ext目录下. cd ./ext/pcntl /opt/server/php5/bin/phpize ./configure \ --with-php-confi ...
- Android Studio 3.1 Beta 1发布,如何及时下载更新
每次收到Android Studio更新提示,总是延迟一段时间才能下载的到或者更新成功.架梯子也不行.而且更新检测也是时断时续.Android Studio 3.0.1使用一段时间,多开几个工程.经常 ...