L
来源:互联网 发布:b超单上的数据怎么看 编辑:程序博客网 时间:2024/04/28 08:25
Donald Duck works as a postman for the Walt Disney Studios. He delivers children’s letters from all over the world to his friends, which are cartoon characters. The Studios has three cases for the letters, with nine sections in each case. Every section has the name of the receiver on it. All cases stand in a row as it is shown at the picture below.
Donald Duck have brought n letters today. Initially, he stands near the leftmost case. He has to make one step to go to the neighboring case or to the previous one. How many steps will he make until he puts all the letters into the respective sections, if he does this in the order they are in his bag?
The first line contains an integer n that is the amount of letters in Donald’s bag (1 ≤ n ≤ 1 000). The following n lines contain receivers of the letters in the order they are in the bag.
Output the number of steps Donald should make to put all the letters into the cases.
4AuroraTianaArielMulan
5
题意:
三个盒子上面每个有9个不同的信箱,相邻的盒子之间的距离为1,要将n封信放入不同信箱,问总共需要走几步》
思路:
预处理一下各个名字在哪个case里面,然后在按照输入顺序移动即可!
代码:
#include<bits./stdc++.h>using namespace std;int main(){//freopen("aaa.txt","r",stdin);int n,i,x,y,sum=0;string s;char c;map<char,int>a;a['A']=0;a['P']=0; a['O']=0; a['R']=0;a['B']=1; a['M']=1; a['S']=1;a['D']=2; a['G']=2; a['J']=2; a['K']=2; a['T']=2; a['W']=2; cin>>n;cin>>s; c=s[0];x=a[c]; sum=x;for(i=1;i<n;i++){cin>>s;c=s[0];y=a[c];sum+=fabs(y-x);x=y;}cout<<sum<<endl;return 0;}
心得:
今天5小时 和队友就AC了两个水题,好气好气好气好气 !!!!!!!!!!!!!!!!!!感觉自己弱爆了
0 0
- l
- .,l
- l
- l
- l
- ';l
- L
- l【
- ,l,
- L
- l
- L
- L
- L
- L
- L
- L
- L
- Java常用类之【日期相关类】
- mui开发app之多图压缩与上传(仿qq空间说说发表)
- 【MPI学习2】MPI并行程序设计模式:对等模式 & 主从模式
- [leetcode]Text Justification
- HDU 5245 Joyful(概率 期望)
- L
- openGL—绘制简单二维图形
- 电影:年轻气盛 (Youth)内附资源
- 【MPI学习3】MPI并行程序设计模式:不同通信模式MPI并行程序的设计
- 在程序中定义一个基类Person类,由这个基类派生出Teacher(教师)类和Leader(领导)类。采用多继承的方式由这两个类派生出Teacher_Leader类。并且满足以下要求:
- BIEE-3、客制化应用
- 【MPI学习4】MPI并行程序设计模式:非阻塞通信MPI程序设计
- 学习笔记3
- laravel学习笔记(5)— Blade模板引擎