School Personal Contest #1 (Codeforces Beta Round #38)---A. Army
2 seconds
256 megabytes
standard input
standard output
The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n,
where 1 is the lowest rank and n is the highest rank.
One needs exactly di years
to rise from rank i to rank i + 1. Reaching a certain
rank i having not reached all the previous i - 1 ranks
is impossible.
Vasya has just reached a new rank of a, but he dreams of holding the rank of b.
Find for how many more years Vasya should serve in the army until he can finally realize his dream.
The first input line contains an integer n (2 ≤ n ≤ 100).
The second line contains n - 1 integers di (1 ≤ di ≤ 100).
The third input line contains two integers a and b (1 ≤ a < b ≤ n).
The numbers on the lines are space-separated.
Print the single number which is the number of years that Vasya needs to rise from rank a to rank b.
3
5 6
1 2
5
3
5 6
1 3
11
解题思路:就是简单的求区间和。
直接开个和数组,a[i]代表i之前(包含i)的全部数的和。
查询时。直接两个和减一下就可以。
AC代码:
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
#define INF 0x7fffffff int c[105]; int main()
{
#ifdef sxk
freopen("in.txt","r",stdin);
#endif
int n, a, b, t;
while(scanf("%d",&n)!=EOF)
{
c[0] = 0;
scanf("%d", &c[1]);
for(int i=2; i<=n-1; i++){
scanf("%d", &t);
c[i] = c[i-1] + t;
}
scanf("%d%d", &a, &b);
printf("%d\n", c[b-1] - c[a-1]);
}
return 0;
}
School Personal Contest #1 (Codeforces Beta Round #38)---A. Army的更多相关文章
- D. Frets On Fire 【二分,前缀和】 (Codeforces Global Round 2)
题目传送门:http://codeforces.com/contest/1119/problem/D D. Frets On Fire time limit per test 1.5 seconds ...
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)
A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- Codeforces Beta Round #16 E. Fish (状压dp)(概率dp)
Codeforces Beta Round #16 (Div. 2 Only) E. Fish 题目链接:## 点击打开链接 题意: 有 \(n\) 条鱼,每两条鱼相遇都会有其中一只吃掉对方,现在给你 ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #69 (Div. 2 Only)
Codeforces Beta Round #69 (Div. 2 Only) http://codeforces.com/contest/80 A #include<bits/stdc++.h ...
- Codeforces Beta Round #40 (Div. 2)
Codeforces Beta Round #40 (Div. 2) http://codeforces.com/contest/41 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #14 (Div. 2)
Codeforces Beta Round #14 (Div. 2) http://codeforces.com/contest/14 A 找最大最小的行列值即可 #include<bits/s ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
随机推荐
- BackboneJS and UnderscoreJS
介绍 来自API(backbone能做什么?) 当我们开发含有大量Javascript的web应用程序时,首先你需要做的事情之一便是停止向DOM对象附加数据. 通过复杂多变的jQuery选择符和回调 ...
- JSP学习笔记 - 内置对象 Response
1.response.addHeader("refresh","2"): 制定页面刷新时间 2.response.addHeader("refresh ...
- struts2配置文件加载顺序
struts2配置文件加载顺序: struts-default.xml/ struts-plugin.xml/ struts.xml/ struts.properties/ web.xml
- Jmeter的面板介绍
一.jmeter面板介绍,这里是5.1.1版本 1.jmeter面板大致分为菜单区,图标区,目录树以及详细配置区域. 2.大多数人用着英文的面板不太舒服,可以在options里切换jmeter的语言 ...
- jmeter普通的接口测试
摘自:后知者.https://www.cnblogs.com/houzhizhe/p/6838731.html jmeter可以做接口测试,其中接口测试的简单操作包括做http脚本(发get/post ...
- BZOJ 1058: [ZJOI2007]报表统计 multiset + 卡常
Code: #include<bits/stdc++.h> #define maxn 600000 #define inf 1000000000 using namespace std; ...
- 总结struts2 iterator status的用法
1:#status.odd 是否奇数行 2:#status.count 当前行数 3:#status.index 当前行的序号,从0开始『#status.count=#status.index+1』 ...
- MAC 打开Chrome打开开发者工具的快捷键
mac下safari和chrome打开开发者工具的快捷键相同,都是 option(alt)+command+i 这个是我的默认配置,没有更改过的.
- mongodb--命令练习
windows10安装下载mongodb # 官网或镜像地址下载mongodb exe 二进制安装包 # 安装时选用custorm 去除勾选compass可视化工具 # 安装完成创建data文件,修改 ...
- mysql如何将一个字段多个类型串成一个字符串?
结论 先说结论,可以使用group_concat group by的组合实现多行变一行,将一个字段的多个类型串成一个字段 需求: 如题,一个字段如电影类别,一部电影可以是多个类别,如喜剧.动作片等,其 ...