[Codeforces Round #247 (Div. 2)] A. Black Square
A. Black Square
1 second
256 megabytes
standard input
standard output
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules of the game, Jury must use this second to touch the corresponding strip to make the square go away. As Jury is both smart and lazy, he counted that he wastes exactly ai calories on touching the i-th strip.
You've got a string s, describing the process of the game and numbers a1, a2, a3, a4. Calculate how many calories Jury needs to destroy all the squares?
The first line contains four space-separated integers a1, a2, a3, a4 (0 ≤ a1, a2, a3, a4 ≤ 104).
The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character of the string equals "1", if on the i-th second of the game the square appears on the first strip, "2", if it appears on the second strip, "3", if it appears on the third strip, "4", if it appears on the fourth strip.
Print a single integer — the total number of calories that Jury wastes.
1 2 3 4
123214
13
1 5 3 2
11221
13 题解:直接模拟。 代码:
#include<stdio.h>
#include<string.h>
#include<stdbool.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<time.h> #define rep(i,a,b) for(i=(a);i<=(b);i++)
#define red(i,a,b) for(i=(a);i>=(b);i--)
#define sqr(x) ((x)*(x))
#define clr(x,y) memset(x,y,sizeof(x))
#define LL long long int i,j,n,m,sum,
a[]; char b[]; void pre()
{
clr(a,);
clr(b,'\0');
sum=;
} int init()
{
rep(i,,)
scanf("%d",&a[i]);
getchar();
scanf("%s",b);
return ;
} int main()
{
int i,len; pre();
init();
len=strlen(b);
len--; rep(i,,len)
sum+=a[b[i]-'']; printf("%d\n",sum); return ;
}
[Codeforces Round #247 (Div. 2)] A. Black Square的更多相关文章
- Codeforces Round #247 (Div. 2) ABC
Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431 代码均已投放:https://github.com/illuz/Wa ...
- Codeforces Round #599 (Div. 2) A. Maximum Square 水题
A. Maximum Square Ujan decided to make a new wooden roof for the house. He has
- Codeforces Round #599 (Div. 2) A. Maximum Square
Ujan decided to make a new wooden roof for the house. He has nn rectangular planks numbered from 11 ...
- Codeforces Round #247 (Div. 2) B - Shower Line
模拟即可 #include <iostream> #include <vector> #include <algorithm> using namespace st ...
- Codeforces Round #249 (Div. 2) A. Black Square
水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...
- Codeforces Round #247 (Div. 2)
A.水题. 遍历字符串对所给的对应数字求和即可. B.简单题. 对5个编号全排列,然后计算每种情况的高兴度,取最大值. C.dp. 设dp[n][is]表示对于k-trees边和等于n时,如果is== ...
- Codeforces Round #247 (Div. 2) C题
赛后想了想,然后就过了.. 赛后....... 我真的很弱啊!想那么多干嘛? 明明知道这题的原型就是求求排列数,这不就是 (F[N]-B[N]+100000007)%100000007: F[N]是1 ...
- Codeforces Round #247 (Div. 2) C. k-Tree (dp)
题目链接 自己的dp, 不是很好,这道dp题是 完全自己做出来的,完全没看题解,还是有点进步,虽然这个dp题比较简单. 题意:一个k叉树, 每一个对应权值1-k, 问最后相加权值为n, 且最大值至少为 ...
- Codeforces Round #247 (Div. 2) D. Random Task
D. Random Task time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- android4.0默认界面旋转180
不巧新拿的android4.0默认启动画面和正常显示旋转了180度,即为倒立的.原来是屏输出为倒的,查找得知可以做旋转: 步骤: 一:先把这个加上 然后加上属性ro.sf.hwrotation = 1 ...
- Why Memory Barrier?
引言:xchg做了什么? 首先,xchg eax, ecx并不会比mov edx, eax + mov eax, ecx + mov ecx, edx这三条指令加一起快,原因是xchg有副作用. Mi ...
- 【转】FAE及其发展前景
原文网址:http://blog.sina.com.cn/s/blog_6e80c27b0100okd9.html FAE Field Application Engineer(现场应用工程师) ,其 ...
- javascript笔记2之数据类型
/* var box; alert(typeof box); //box是Undefined类型,值是undefined,类型返回的字符串是undefined var box = true; aler ...
- cocos2d-x核心基础类
Application 应用程序入口类 EGLView 绘图句柄 Director Node Layer Scene
- 在CentOS中编译安装VIM 7.3
默认安装的 Vim 不带有多字符支持,所以不支持中文.无论是将 CentOS 本来的语系改为中文还是将 Vim 的语系设置改为中文,都不能正常显示中文.为了在 Vim 中能够正常处理中文,我们需要在编 ...
- 企业生产环境中linux系统分区的几种方案
方案1:针对网站集群架构中的某个节点服务器分区 该服务器上的数据有多份(其他节点也有)且数据不太重要,建议分区方案如下: /boot: 200MB swap: 物理内存的1.5倍,当内存大于或等于8G ...
- Android AdapterView View的复用机制 分析
对于ListView.GridView相信大家都不陌生,重写个BaseView,实现对于的几个方法,然后就完毕了我们的界面展示.而且在大部分情况下,我们载入特别多的Item也不会发生OOM,大家也都明 ...
- tomcat配置数据源
1.修改conf下的context.xml,在<context>标签中添加: <Resource name="jdbc/soa" auth="Conta ...
- ios按钮点击时的灰色框
a,button,input,textarea{-webkit-tap-highlight-color: rgba(0,0,0,0;)}