题目描述

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的更多相关文章

  1. HUST 1601 Shepherd

    间隔小的时候dp预处理,大的时候暴力..正确做法不会... dp[i][j]表示以i为开头,间隔为j的和,递推:dp[i][j] = dp[i + j][j] + a[i] 测试数据中间隔可能是0.. ...

  2. Shepherd – 在应用程序中轻松实现引导功能

    Shepherd 是一个指导用户使用应用程序的 JavaScript 库.它使用 Tether——另一个开源库,实现所有的步骤.Tether 确保你的步骤不会溢出屏幕或被剪裁.你可以很容易地指导用户使 ...

  3. 【BZOJ】1601: [Usaco2008 Oct]灌水(kruskal)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1601 很水的题,但是一开始我看成最短路了T_T 果断错. 我们想,要求连通,对,连通!连通的价值最小 ...

  4. 【HDOJ】1601 Galactic Import

    Dijkstra. /* 1601 */ #include <cstdio> #include <cstring> #include <cstdlib> #defi ...

  5. webservice取文件修改时间,返回1601/1/1 8:00:00

    若文件查找不到,则会返回1601/1/1 8:00:00,若能正确查找到该文件,则返回正确的修改时间.

  6. BZOJ 1601 [Usaco2008 Oct]灌水

    1601: [Usaco2008 Oct]灌水 Time Limit: 5 Sec  Memory Limit: 162 MB Description Farmer John已经决定把水灌到他的n(1 ...

  7. <hdu - 1600 - 1601> Leftmost Digit && Rightmost Digit 数学方法求取大位数单位数字

    1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * ...

  8. 1601: [Usaco2008 Oct]灌水

    1601: [Usaco2008 Oct]灌水 Time Limit: 5 Sec  Memory Limit: 162 MB Submit: 1342  Solved: 881 [Submit][S ...

  9. 一本通1601【例 5】Banknotes

    1601:[例 5]Banknotes 时间限制: 1000 ms         内存限制: 524288 KB [题目描述] 原题来自:POI 2005 Byteotian Bit Bank (B ...

随机推荐

  1. 系统安装SQL Sever2000后1433端口未开放,如何打开1433端口的解决方法

    这篇文章主要针对Win2003系统安装SQL Sever2000后1433端口未开放,如何打开1433端口的解决方法. 用了几年的Windows2003和SQL Server2000了,不过这个问题倒 ...

  2. Symbol.iterator的理解

    https://blog.csdn.net/margin_0px/article/details/82971545

  3. Go工具和调试详解

    https://blog.csdn.net/happyanger6/article/details/78724594/ https://blog.csdn.net/u012210379/article ...

  4. python concurrent.futures包使用,捕获异常

    concurrent.futures的ThreadPoolExecutor类暴露的api很好用,threading模块抹油提供官方的线程池.和另外一个第三方threadpool包相比,这个可以非阻塞的 ...

  5. 【原】list<T>排序

    继承IComparable #region IComparable        public int CompareTo(object  obj)    {        if(obj is Sce ...

  6. JQuery------各种版本下载

    转载: http://www.jq22.com/jquery-info122

  7. ios开发之--WKWebView的使用

    WKWebView是ios 8 出来的,是为了解决UIWebView卡慢,占用内存过大的问题. 在以往时候,如果用UIWebView加载加载网页的时候,卡慢现象会很严重,有时候往往会卡到一个页面无法动 ...

  8. JavaScript-this理解

    javascript this可以绑定到:全局对象,自己定义的对象,用构造函数生成的对象,通过call或者apply更改绑定的对象    1.全局对象  function globalTest(nam ...

  9. LNMP 简介

    LNMP 代表的就是:Linux 操作系统下,Nginx + MySQL + PHP 这种网站服务器架构 工作流程:Nginx 直接处理静态请求,动态请求会转发给 php-fpm ( php 是作为一 ...

  10. 3dmax osg格式导出插件 osgExp OpenSceneGraph Max Exporter

    https://sourceforge.net/projects/osgmaxexp/files/OpenSceneGraph%20Max%20Exporter/