ZCMU-1036
2016-12-29 07:49
211 查看
1036: Shepherd
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 140 Solved: 29
[Submit][Status][Web
Board]
Description
Hehe keeps a flock of sheep, numbered from 1 to n and each with a weight wi. To keep the sheep healthy, he prepared some training for his sheep. Everytime he selects a pair of numbers (a,b), and chooses the sheep withnumber a, a+b, a+2b, … to get trained. For the distance between the sheepfold and the training site is too far, he needs to arrange a truck with appropriate loading capability to transport those sheep. So he wants to know the total weight of the
sheep he selected each time, and he finds you to help him.
Input
There’re several test cases. For each case:The first line contains a positive integer n (1≤n≤10^5)---the number of sheep Hehe keeps.
The second line contains n positive integer wi(1≤n≤10^9), separated by spaces, where the i-th number describes the weight of the i-th sheep.
The third line contains a positive integer q (1≤q≤10^5)---the number of training plans Hehe prepared.
Each following line contains integer parameters a and b (1≤a,b≤n)of the corresponding plan.
Output
For each plan (the same order in the input), print the total weight of sheep selected.Sample Input
51 2 3 4 5
3
1 1
2 2
3 3
Sample Output
156
3
【解析】
这道题的大致意思就是给你个数组,然后三次查找,给你选定范围比如说1 1则是从1开始每隔1个数,这道题的话我超时了三次,最后是在两地方做了改动一个就是算了数组的总和,另一个就是判断如果p=1并且q=1那就直接输出总和就好。
#include<iostream> #include<string> #include<vector> #include<cstdio> using namespace std; vector<int>a; int main() { int n,m,i,p,q,num,j; long long sum1,sum2; while(~scanf("%d",&n)) { a.clear(); sum1=0; for(i=0;i<n;i++) { scanf("%d",&num); a.push_back(num); sum1+=num; } scanf("%d",&m); while(m--) { sum2=0; scanf("%d%d",&p,&q); if(p==1&&q==1) { printf("%lld\n",sum1); continue; } for(j=p-1;j<n;j+=q) sum2+=a[j]; printf("%lld\n",sum2); } } return 0; }
相关文章推荐
- BZOJ1036 树的统计
- NYOJ 1036 非洲小孩
- URAL 1036 Lucky Tickets(基础dp)
- summer 1036 Red Pocket
- zcmu 1617: 补提交
- 1036. 跟奥巴马一起编程(15)
- BZOJ 1036: [ZJOI2008]树的统计Count (树链剖分 + 线段树)
- codevs 1036 商务旅行 题解报告
- 1036. 跟奥巴马一起编程(15)
- ZCMU—1758
- [hihocoder1036]Trie图
- ZCMU—1306
- 【bzoj1036】[ZJOI2008]树的统计Count 树链剖分+线段树
- ZCMU----1779
- ZCMU-1775-xx
- PAT 1036. 跟奥巴马一起编程(15)
- ZCMU-1183-大数相余
- ZCMU—1373
- ZCMU—1400
- ZCMU-Average speed