您的位置:首页 > 其它

Night at the Museum(水题)

2016-10-19 16:16 465 查看
</pre><p></p><div id="problem_number_container" class="ui-buttonset" style="margin:auto; color:rgb(34,34,34); font-family:Verdana,Arial,sans-serif; font-size:14px; text-align:center"><label for="problem_numberA" class="ui-button ui-widget ui-state-default ui-button-text-only ui-state-active ui-corner-left" style="display:inline-block; position:relative; padding:0px; margin-right:-0.3em; vertical-align:middle; overflow:visible; font-size:1em; border:1px solid rgb(170,170,170); color:rgb(33,33,33); margin-left:0px"><span class="ui-button-text" style="display:block; padding:0.4em 1em">A</span></label> <input type="radio" name="problem_number" id="problem_numberB" value="B" class="ui-helper-hidden-accessible" style="border-width:0px; height:1px; margin:-1px; overflow:hidden; padding:0px; position:absolute; width:1px; font-family:Verdana,Arial,sans-serif; font-size:1em" /><label for="problem_numberB" class="ui-button ui-widget ui-state-default ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:-0.3em; vertical-align:middle; overflow:visible; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85); margin-left:0px"><span class="ui-button-text" style="display:block; padding:0.4em 1em">B</span></label> <input type="radio" name="problem_number" id="problem_numberC" value="C" class="ui-helper-hidden-accessible" style="border-width:0px; height:1px; margin:-1px; overflow:hidden; padding:0px; position:absolute; width:1px; font-family:Verdana,Arial,sans-serif; font-size:1em" /><label for="problem_numberC" class="ui-button ui-widget ui-state-default ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:-0.3em; vertical-align:middle; overflow:visible; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85); margin-left:0px"><span class="ui-button-text" style="display:block; padding:0.4em 1em">C</span></label> <input type="radio" name="problem_number" id="problem_numberD" value="D" class="ui-helper-hidden-accessible" style="border-width:0px; height:1px; margin:-1px; overflow:hidden; padding:0px; position:absolute; width:1px; font-family:Verdana,Arial,sans-serif; font-size:1em" /><label for="problem_numberD" class="ui-button ui-widget ui-state-default ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:-0.3em; vertical-align:middle; overflow:visible; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85); margin-left:0px"><span class="ui-button-text" style="display:block; padding:0.4em 1em">D</span></label> <input type="radio" name="problem_number" id="problem_numberE" value="E" class="ui-helper-hidden-accessible" style="border-width:0px; height:1px; margin:-1px; overflow:hidden; padding:0px; position:absolute; width:1px; font-family:Verdana,Arial,sans-serif; font-size:1em" /><label for="problem_numberE" class="ui-button ui-widget ui-state-default ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:-0.3em; vertical-align:middle; overflow:visible; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85); margin-left:0px"><span class="ui-button-text" style="display:block; padding:0.4em 1em">E</span></label> <input type="radio" name="problem_number" id="problem_numberF" value="F" class="ui-helper-hidden-accessible" style="border-width:0px; height:1px; margin:-1px; overflow:hidden; padding:0px; position:absolute; width:1px; font-family:Verdana,Arial,sans-serif; font-size:1em" /><label for="problem_numberF" class="ui-button ui-widget ui-state-default ui-button-text
4000
-only ui-corner-right" style="display:inline-block; position:relative; padding:0px; margin-right:-0.3em; vertical-align:middle; overflow:visible; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85); margin-left:0px"><span class="ui-button-text" style="display:block; padding:0.4em 1em">F</span></label></div><div class="plm" style="text-align:center; font-size:12pt; color:rgb(34,34,34); clear:both"><div class="ptt" id="problem_title" style="font-size:18pt; font-weight:bold; color:blue; padding:10px"><span style="color:green">A - </span>Night at the Museum</div><span id="crawlSuccess" class="crawlInfo" style="display:inline"><strong>Time Limit:</strong><span id="timeLimit">1000</span>MS     <strong>Memory Limit:</strong><span id="memoryLimit">262144</span>KB     <strong>64bit IO Format:</strong><span id="_64IOFormat">%I64d & %I64u</span></span><div id="problem_opt" style="font-size:12px; margin-top:10px"><a target=_blank target="_blank" id="submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; font-family:Verdana,Arial,sans-serif; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85)"><span class="ui-button-text" style="display:block; padding:0.4em 1em">Submit</span></a> <a target=_blank target="_blank" id="problem_status" href="http://vjudge.net/contest/137431#status//A/0" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85)"><span class="ui-button-text" style="display:block; padding:0.4em 1em">Status</span></a></div></div><div style="color:rgb(34,34,34); font-family:Verdana,Arial,sans-serif; font-size:14px; width:960px; margin:auto"><div id="desc_A_0" class="desc_template"><div class="vj_description"><p class="pst" style="font-family:Arial,Helvetica,sans-serif; font-size:18pt; font-weight:bold; color:blue; margin-bottom:0px">Description</p><div class="textBG" style="padding:10px; border:2px dotted; font-family:'Times New Roman',Times,serif; font-size:17px; background-color:rgb(234,235,255)"><p>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<span class="tex-font-style-it">embosser</span> and was to take stock of the whole exposition.</p><p><span class="tex-font-style-it">Embosser</span> 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 '<span class="tex-font-style-tt">a</span>'. Other letters are located as shown on the picture:</p><center><img class="tex-graphics" src="https://odzkskevi.qnssl.com/d2385b366911eef491366f05be0ef7c4" alt="" style="max-width:100%; max-height:100%" /></center><p>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 '<span class="tex-font-style-tt">a</span>'.</p><p>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.</p></div></div><div class="vj_input"><p class="pst" style="font-family:Arial,Helvetica,sans-serif; font-size:18pt; font-weight:bold; color:blue; margin-bottom:0px">Input</p><div class="textBG" style="padding:10px; border:2px dotted; font-family:'Times New Roman',Times,serif; font-size:17px; background-color:rgb(234,235,255)"><div class="input-specification"><div class="section-title"><p>The only line of input contains the name of some exhibit — the non-empty string consisting of no more than <span class="tex-span" style="font-size:21.25px">100</span> characters. It's guaranteed that the string consists of only lowercase English letters.</p></div></div></div></div><div class="vj_output"><p class="pst" style="font-family:Arial,Helvetica,sans-serif; font-size:18pt; font-weight:bold; color:blue; margin-bottom:0px">Output</p><div class="textBG" style="padding:10px; border:2px dotted; font-family:'Times New Roman',Times,serif; font-size:17px; background-color:rgb(234,235,255)"><div class="output-specification"><div class="section-title"><p>Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.</p></div></div></div></div><div class="vj_sampleInput"><p class="pst" style="font-family:Arial,Helvetica,sans-serif; font-size:18pt; font-weight:bold; color:blue; margin-bottom:0px">Sample Input</p><div class="textBG" style="padding:10px; border:2px dotted; font-family:'Times New Roman',Times,serif; font-size:17px; background-color:rgb(234,235,255)"><div class="sample-tests"><div class="section-title"><div class="sample-test"><div class="input" style="border:1px solid rgb(136,136,136)"><div class="title" style="border-bottom-width:1px; border-bottom-style:solid; border-bottom-color:rgb(136,136,136); font-family:arial; font-weight:bold; padding:0.25em; background-color:rgb(255,255,255)">Input</div><pre style="white-space:pre-wrap; word-wrap:break-word; line-height:1.25em; margin-top:0px; margin-bottom:0px; padding:0.25em; background-color:rgb(239,239,239)">zeus


Output
18


Input
map


Output
35


Input
ares


Output
34


Hint

 



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.

水题:

#include<stdio.h> 
#include<cstring>
#include<cmath>
#include<iostream>
int main()
{
char a[105];area
int ans=0;
scanf("%s",a+1);
a[0]='a';
for(int i=0;i<strlen(a)-1;i++)	{
ans+=min(min(abs(a[i]-a[i+1]),abs(a[i+1]+26-a[i])),abs(a[i]+26-a[i+1]));
}
printf("%d\n",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: