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++. ...
随机推荐
- 26-Ubuntu-文件和目录命令-其他命令-管道
管道 Linux允许将一个命令的输出可以通过管道作为另一个命令的输入. 可以理解为现实生活中的管子,管子的一头塞东西进去,另一头取出来,这里的 | 左右分为两端,左端塞东西(写),右端取东西(读). ...
- 01Microsoft SQL Server
Microsoft SQL Server Microsoft SQL Server 是Microsoft 公司推出的关系型数据库管理系统.具有使用方便可伸缩性好与相关软件集成程度高等优点,可跨越膝上型 ...
- Eigen库笔记整理(一)
首先熟悉Eigen库的用途,自行百度. 引入头文件: // Eigen 部分 #include <Eigen/Core> // 稠密矩阵的代数运算(逆,特征值等) #include < ...
- Linux安装redis并且连接内网的redis
1.安装redis步骤 1.首先准备工作 [root@10-100-14-130 ~]# yum install gcc-c++ yum install wget 2.推荐进入到linux路径/ ...
- jquery的delegate()方法
delegate() 方法为指定的元素(属于被选元素的子元素)添加一个或多个事件处理程序,并规定当这些事件发生时运行的函数. 使用 delegate() 方法的事件处理程序适用于当前或未来的元素(比如 ...
- document.write() 和 document.writeln区别
document.write() 和 document.writeln 都是JavaScript向客户端写入的方法,writeln是以行方式输出的,但并不是指页面实际效果中的换行,两种方法在查看源代码 ...
- thymeleaf的使用及配置
* th:action <form id="login" th:action="@{/login}">......</form> ...
- webpack之webpack-dev-server 与 webpack-hot-server
最近在弄框架,用到了webpack打包,当然不可避免的遇到了开发实际问题.在实际开发中,我们不可能改一个文件,就去构建一次,于是想到了实时更新.查看webpack,看到了webpack-dev-ser ...
- ZOJ - 3987 - Numbers (大数 + 贪心)
参考自:https://blog.csdn.net/u013534123/article/details/78484494 题意: 给出两个数字n,m,把n分成m份,使得以下最小 思路: 或运算只有0 ...
- plot3d
plot3d plot3D a format for structured grid data that was popularized by NASA's CFD visualization Aut ...