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++. ...
随机推荐
- LR性能分析随笔(一)
一.关键词 吞吐量:对于吞吐量,单位时间内吞吐量越大,说明服务器的处理能力越好:而请求数仅表示客户端向服务器发出的请求数,与吞吐量一般成正比关系. HTTP:HTTP404表示文件或目录没有找到.有些 ...
- HWND CWND 转换
一.区别HWND是句柄,CWnd是MFC窗体类,CWnd中包含HWND句柄成员对象是m_hWnd.HWND是Windows系统中对所有窗口的一种标识,即窗口句柄.这是一个SDK概念. CWnd是M ...
- jQuery鼠标划入划出
今天来简单的谈谈jQuery的一个划入划出的方法,.首先划入划出能想到的东西有哪些呢,. 1:hover 2:mouseenter/mouseleave 3:mouseover/mouseout. 一 ...
- blog笔录1
(1)虚拟主机 (2)部署 部署完成后刷新页面会看到笑脸,在Home分组下控制器Application/Home/Controller/IndexController.class.php下定义显示 ( ...
- Python 操作excel day5
一.Python操作excel python操作excel使用xlrd.xlwt和xlutils模块 1.xlrd模块是读取excel的: 2.xlwt模块是写excel的: 3.xlutils是用来 ...
- Python orm基础
ORM 对象映射关系程序. 通过orm将编程语言的对象模型和数据库的关系模型建立映射关系,这样我们在使用编程语言对数据库进行操作的时候可以直接使用编程语言的对象模型进行操作就可以了,而不用直接使用sq ...
- layer iframe层ajax回调弹出layer.msg()
ajax success方法 success: function(data){ layer.msg("输入你需要的提示",{time:1000,end:function(){ // ...
- UVA - 208 Firetruck(并查集+dfs)
题目: 给出一个结点d和一个无向图中所有的边,按字典序输出这个无向图中所有从1到d的路径. 思路: 1.看到紫书上的提示,如果不预先判断结点1是否能直接到达结点d,上来就直接dfs搜索的话会超时,于是 ...
- Struts2输入错误处理
1.Action类继承ActionSupport父类,将result的name属性设置为<result name="input">/inputError.jsp< ...
- linux初步学习有感
经过了一段时间对linux的接触,从最开始接触到的deepin到后来我最喜欢的KaliLinux,感受到了这个我曾经并不了解的操作系统的独特魅力. 我是到了大学才知道linux这个系统的,但是在小时候 ...