题目描述

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. Java动态调用类中方法

    在Java中,调用类的方法有两种方式:对于静态方法可以直接使用类名调用,对于非静态方法必须使用类的对象调用.反射机制提供了比较另类的调用方式,可以根据需要指定要调用的方法,而不必在编程时确定.调用的方 ...

  2. Linux Top命令详解(载自百度经验)

    Linux系统可以通过top命令查看系统的CPU.内存.运行时间.交换分区.执行的线程等信息.通过top命令可以有效的发现系统的缺陷出在哪里.是内存不够.CPU处理能力不够.IO读写过高. 1 使用S ...

  3. eclipse中设置文件的编码格式为utf-8

    1.可以在 eclipse 中配置 workspace 项下 text file encoding 属性的值来决定此工作区间下所有的 eclipse 项目的文档的编码属性. Window-->P ...

  4. [转]Tomcat的部署

    1.1 Context descriptors Tomcat4中的Manager和Admin管理工具其实就是利用它来部署的.在Tomcat5中提出了Context descriptor这个概念,且为其 ...

  5. [AX]AX2012 Interaction class

    Ax2012 Client的form如果属性FormTemplate设置为DetailsPage或者ListPage,则必须同时设置属性InteractionClass为相应的Interaction类 ...

  6. Data Guard启动实时日志应用

    1. REDO数据实时应用 启动实时应用的优势在于,REDO数据不需要等待归档完成,接收到即可被应用,这样执行角色切换时,操作能够执行得更快,因为日志是被即时应用的. 要启动实时应用也简单,前提是St ...

  7. ASP代码审计学习笔记 -5.文件下载漏洞

    文件下载漏洞 漏洞代码: <% function download(f,n) on error resume next Set S=CreateObject("Adodb.Stream ...

  8. linux 设置分辨率(转)

    linux 设置分辨率 如果你需要在linux上设置显示屏的分辨率,分两种情况:分辨率模式存在与分辨率模式不存在,具体如下. 1,分辨率模式已存在 1)如何查询是否存在: 图形界面:在System S ...

  9. 【MATLAB】评价二值分割结果的函数

    根据PASCAL challenges的标准:intersection-over-union score,所写的matlab评价程序,处理二值图像. 其思想即分割结果与Ground Trueth的交集 ...

  10. 【前端开发】 JS面试题整理

    1.截取字符串abcdace的acealert('abcdace'.substring(4)); 2.规避javascript多人开发函数重名问题命名空间封闭空间js模块化mvc(数据层.表现层.控制 ...