URAL 2023. Donald is a postman (预处理)
来源:互联网 发布:淘宝浏览器插件 编辑:程序博客网 时间:2024/05/29 04:02
2023. Donald is a postman
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
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?
Input
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
Output the number of steps Donald should make to put all the letters into the cases.
Sample
4AuroraTianaArielMulan
5
解析:预处理一下各个名字在哪个case里面,然后再按照输入顺序移动即可。
AC代码:
#include <cstdio>#include <string>#include <iostream>using namespace std;int a[30];int main(){ #ifdef sxk freopen("in.txt", "r", stdin); #endif //sxk for(int i=0; i<26; i++){ if(i == 'A' - 'A' || i == 'P' - 'A' || i == 'O' - 'A' || i == 'R' - 'A') a[i] = 1; else if(i == 'B' - 'A' || i == 'M' - 'A' || i == 'S' - 'A') a[i] = 2; else if(i == 'D' - 'A' || i == 'G' - 'A' || i == 'J' - 'A' || i == 'K' - 'A' || i == 'T' - 'A' || i == 'W' - 'A') a[i] = 3; else a[i] = 0; } int n; string s; while(scanf("%d", &n)==1){ int ans = 0, now = 1; for(int i=0; i<n ; i++){ cin>>s; ans += a[ s[0] - 'A' ] > now ? a[ s[0] - 'A' ] - now : now - a[ s[0] - 'A' ]; now = a[ s[0] - 'A' ]; } printf("%d\n", ans); } return 0;}
0 0
- URAL 2023. Donald is a postman (预处理)
- ACM ICPCNEERC. Eastern Subregional Contest Donald is a postman
- UVALive 7263 Today Is a Rainy Day(BFS预处理)
- 【URAL 1900】Brainwashing Device(预处理区间和+DP)
- BFS预处理 hihoCoder1251 Today Is a Rainy Day
- UVALive - 7263 Today Is a Rainy Day (BFS预处理)
- Ural 1260. A nudnik photographer(dp)
- Ural 1260 A nudnik photographer(DP)
- HDU 2102 A计划 (BFS + 预处理)
- URAL 1032 A
- ural 1740 Deer is Better!
- URAL - 1740 - Deer is Better!
- Deer is Better! ural 1740
- URAL 1181 Cutting a Painted Polygon(解题报告)
- Search for a Hiding-Place (URAL 1762)
- ural 1032 Find a Multiple (鸽巢原理)
- A.1.17预处理
- Postman(网页调试)
- 一个openwrt编译错误的解决办法----安装xz工具
- hive 中转义符使用问题
- easyui中关于值的设置与获取
- NSFileManager处理目录的一些方法
- 操作系统之内存管理1
- URAL 2023. Donald is a postman (预处理)
- C语言union的一个例子的讨论
- 设计模式学习
- ID3算法思想解析
- 使用NFC-SD手机和SD_SWP卡进行移动支付
- 寒城攻略:Listo 教你 25 天学会 Swift 语言 - 21 Nested Types
- 安卓第四记
- zencart建站后台设计介绍
- java中实现js中的alert功能