ZCMU—1036
来源:互联网 发布:中央已经决定了知乎 编辑:程序博客网 时间:2024/06/05 10:51
1036: Shepherd
Time Limit: 1 Sec Memory Limit: 128 MB[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 with number 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
Sample Output
【分析】
题意:第一行输入一个数字n,第二行输入n个数字,第三行输入数字q,表示接下来又q个询问,接下来的q行,每行有两个数字a,b,要求计算根据每组a,b,在n个数字中从第a个开始,相隔b,2*b,3*b ……个位置的数字的和,输出这个和。
#include<iostream>#include<cstdio>using namespace std;int main(){ int a[100000]; int n; while(~scanf("%d",&n)) { long long s1=0; for(int i=0;i<n;i++) { scanf("%d",&a[i]); s1+=a[i]; } int pp;scanf("%d",&pp); while(pp--) { long long sum=0; int b,c; scanf("%d%d",&c,&b); if(c==1&&b==1){printf("%lld\n",s1);continue;} for(int i=c-1;i<n;i+=b)sum+=a[i]; printf("%lld\n",sum); } } return 0;}
- ZCMU—1036
- ZCMU-1036
- ZCMU—1678
- ZCMU—1605
- ZCMU—1067
- ZCMU—1607
- ZCMU—1069
- ZCMU—1611
- ZCMU—1606
- ZCMU—1774
- ZCMU—1766
- ZCMU—1752
- ZCMU—1724
- ZCMU—1623
- ZCMU—1689
- ZCMU—1667
- ZCMU—1639
- ZCMU—1668
- iOS native push 小结
- 字符串直接量
- tomcat启动后,页面浏览时报错 Unable to compile class for JSP的解决方案
- 核函数-Kernel Function汇总
- 报打开的文件数过多(Too many open files)
- ZCMU—1036
- 51nod 1099 任务执行顺序【贪心】
- 解决 subject.onNext is not a function
- 点击跳转QQ聊天
- hdoj-【2546 饭卡】
- java面试打击后归来深刻总结分析
- 网络协程编程
- 乘积量化( Product Quantization )近似最近邻搜索 分享
- IIS服务器下载apk文件