HUSTM 1601 - Shepherd
来源:互联网 发布:壹方凌网络是干嘛的 编辑:程序博客网 时间:2024/06/13 23:01
题目描述
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.
输入
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.
输出
For each plan (the same order in the input), print the total weight of sheep selected.
样例输入
5
1 2 3 4 5
3
1 1
2 2
3 3
样例输出
15
6
3
提示
暴力也能过
醉了
#include <iostream>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>#include <stdio.h>using namespace std;int n;int a[100005];int s[100005];int q;int b,c;int main(){ while(scanf("%d",&n)!=EOF) { s[0]=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); s[i]=s[i-1]+a[i]; } scanf("%d",&q); for(int i=1;i<=q;i++) { long long int ans=0; scanf("%d%d",&b,&c); if(c==0) { ans=a[b]; printf("%lld\n",ans); continue; } else { for(int j=b;j<=n;j+=c) ans+=a[j]; } printf("%lld\n",ans); } } return 0;}
- HUSTM 1601 - Shepherd
- HUST 1601 Shepherd
- HUST-1601 - Shepherd 暴力
- Shepherd boy technical support
- Shepherd boy technical support
- POJ-1601
- ZOJ-1601
- zoj 1601
- 1601液晶程序
- fjnu 1601 Hardwood Species
- UVA - 1601(双向BFS)
- uva 1601 dbfs搜索
- CSU 1601: War
- 1601: 名字缩写
- ZCMU—1601
- 操作显存数据(1601)
- 1601: [Usaco2008 Oct]灌水
- HNUSTOJ 1601:名字缩写
- C#实现压缩与解压缩
- ffmpeg命令行实现YUV和RGB之间格式的转换
- EXCEL表写入时问题解决
- Spring容器初始化后执行自定义的业务操作
- Android设备通过wifi连接adb调试
- HUSTM 1601 - Shepherd
- KMP算法
- 多线程下载
- AndFix解析——(中)
- 获取页面Url地址栏后面的参数
- Spring AOP: proxy-target-class 值的意思
- Windows下Mysql错误ERROR 1045 (28000) ERROR 1054 (42S22)以及ERROR 1820 (HY000)的解决
- js开始时间、结束时间比较
- Android Studio使用教程(一)