[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 ...
随机推荐
- 资本助力转型 TCL攻守转换(转型、并购、过冬前一定要保留强大的战略预备队)
吴侨发 9月份,TCL集团(3.92, 0.00, 0.00%)160多位高管启动四天戈壁行.在戈壁行第三天,30多公里的戈壁,差不多等于平路50公里,最后两只队伍走了13个小时.路途的艰辛几乎超过这 ...
- 2014.7.8模拟赛【笨笨当粉刷匠】|bzoj1296 [SCOI]粉刷匠
笨笨太好玩了,农田荒芜了,彩奖用光了,笨笨只好到处找工作,笨笨找到了一份粉刷匠的工作.笨笨有n条木板需要被粉刷.每条木板被分成m个格子,每个格子要被刷成红色或蓝色.笨笨每次粉刷,只能选择一条木板上一段 ...
- Centos 6.5中安装后不能打开emacs的问题
问题的发现过程: 安装了最新的centos版本后发现居然打不开emacs,然后在终端中输入emacs后还是不能打开,出现了下面的提示: emacs: error while loading share ...
- poj 1486 Sorting Slides(二分图匹配的查找应用)
Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...
- javascript:DOM自定义属性的妙用
虽然HTML元素的属性已经十分丰富,但在某些场合下,元素固有的属性无法完成我们的需求: 这个时候,自定义属性就会让问题解决起来比较方便. 比如,下面的栗子: 多张图片点击变化事件:当背景图片为a.jp ...
- 【POJ2114】Boatherds 树分而治之
做广告: #include <stdio.h> int main() { puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog. ...
- Hibernate自增列保存失败的问题
author: hiu 更正说明:今天(2014-07-07)才发现的问题,我把@Id设置在了实体类中的id中,@Id是主键,应该设置在实体类的keyjobno中,之前发的文章可能误导了大家,如今更正 ...
- 使用代码自定义UIView注意一二三
文/CoderAO(简书作者)原文链接:http://www.jianshu.com/p/68b383b129f9著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 当一撮样式一样的视图在 ...
- 巧记--Css选择器
love ------> hate 即: a:link --> a:visited --> a:hover --> a:active a:link ...
- 调试EF源码
在解决方案中添加下载好的EF的源码的引用 在新建项目中添加程序集的引用 添加配置文件中的节点 测试 获取程序集的公钥标记: 使用sn.exe命令 使用reflector