HUSTM 1601 - Shepherd
题目描述
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
间隔小的时候dp预处理,大的时候暴力..正确做法不会... dp[i][j]表示以i为开头,间隔为j的和,递推:dp[i][j] = dp[i + j][j] + a[i] 测试数据中间隔可能是0.. ...
- Shepherd – 在应用程序中轻松实现引导功能
Shepherd 是一个指导用户使用应用程序的 JavaScript 库.它使用 Tether——另一个开源库,实现所有的步骤.Tether 确保你的步骤不会溢出屏幕或被剪裁.你可以很容易地指导用户使 ...
- 【BZOJ】1601: [Usaco2008 Oct]灌水(kruskal)
http://www.lydsy.com/JudgeOnline/problem.php?id=1601 很水的题,但是一开始我看成最短路了T_T 果断错. 我们想,要求连通,对,连通!连通的价值最小 ...
- 【HDOJ】1601 Galactic Import
Dijkstra. /* 1601 */ #include <cstdio> #include <cstring> #include <cstdlib> #defi ...
- webservice取文件修改时间,返回1601/1/1 8:00:00
若文件查找不到,则会返回1601/1/1 8:00:00,若能正确查找到该文件,则返回正确的修改时间.
- BZOJ 1601 [Usaco2008 Oct]灌水
1601: [Usaco2008 Oct]灌水 Time Limit: 5 Sec Memory Limit: 162 MB Description Farmer John已经决定把水灌到他的n(1 ...
- <hdu - 1600 - 1601> Leftmost Digit && Rightmost Digit 数学方法求取大位数单位数字
1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * ...
- 1601: [Usaco2008 Oct]灌水
1601: [Usaco2008 Oct]灌水 Time Limit: 5 Sec Memory Limit: 162 MB Submit: 1342 Solved: 881 [Submit][S ...
- 一本通1601【例 5】Banknotes
1601:[例 5]Banknotes 时间限制: 1000 ms 内存限制: 524288 KB [题目描述] 原题来自:POI 2005 Byteotian Bit Bank (B ...
随机推荐
- xcode修改默认头部注释(__MyCompanyName__) (转)
打开命令行: defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ "ORGANIZATIONNAME&qu ...
- Linux下安装中文宋体
1,#cd /usr/share/fonts/default 2,mkdir -p ./truetype/simsun 3,取得simsun.ttc文件:如果网上下载不到则在windows (c:/w ...
- vs2012修复问题
多装了一个.net framework4.5.1结果vs不能拥,借用了下面这个工具将vs2012从注册表中删除了 就能重装了 http://www.auslogics.com/en/software/ ...
- 我的notepad++
我觉得,做开发的一定要有一个简单,但功能强大的文本编辑器.我比较喜欢notepad++,而且一直使用.准备通过这篇文章分享一下我的notepad++配置. 希望广大notepad++用户,如果有好的配 ...
- nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
当你执行sudo nginx -s reload时出现nginx: [error] open() "/run/nginx.pid" failed (2: No such file ...
- ios开发之--仿购物类详情页面数量添加小功能
话不多说先上图:
- cocos2dx 3.0 scrollview 在android下面背景變綠色了
在windows上面跑的是OK的, 在android下面跑的時候就變成這樣子了:
- javaweb项目中表单生成的验证码以及校验
首先先来看一下项目的结构吧,有两个servlet,一个是进行验证码的生成以及存储的,一个是进行校验的,还有一个jsp页面是用来实现form表单的书写和展示: 我们只需要看这三个就行了,其他的自动忽略: ...
- PHP 简易导出excel 类解决Excel 打开乱码
<?php class exportCsv{ //列名 protected $_column = array(); protected $_reg = array(); public $ret ...
- MegaCli 使用
安装: wget ftp://rpmfind.net/linux/Mandriva/devel/cooker/x86_64/media/non-free/release/megacli-8.02.21 ...