题目描述

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. [原]巧用RenderTexture

    郑重声明:转载请注明出处 U_探索 本文诞生于面试过程中这道题:NGUI如何制作3D角色的显示.(大概是这样)  呵呵 没事出去面试面试,考核考核自己也是一种不错的方式哦!不过现在u3d面试,貌似比以 ...

  2. SpringMVC由浅入深day01_4DispatcherSerlvet.properties

    4 DispatcherSerlvet.properties DispathcerServlet作为springmvc的中央调度器存在,DispatcherServlet创建时会默认从Dispatch ...

  3. SaltStack salt-key 命令

    salt-key is used to manage Salt authentication keys [root@localhost ~]$ salt-key -L # 查看有哪些minion公钥过 ...

  4. 带有ZLIB_LIBRARY_DEBUG的FindZLIB.cmake文件

    CMake自带的FindZLIB.cmake只有ZLIB_LIBRARY,而没有ZLIB_LIBRARY_DEBUG 将下面的代码保存成FindZLIB.cmake,替换掉D:\Program Fil ...

  5. 发送http请求

    public static String httpGetSend(String url) { String responseMsg = ""; HttpClient httpCli ...

  6. 在recycler中写的布局不起作用

    把 LinearLayout 改成 RelativeLayout   ok了 创建的两种方式 1.LayoutInflater.from(parent.getContext()).inflate(R. ...

  7. repr方法字符串输出实例对象的值

    #coding=utf-8 #repr方法字符串输出实例对象的值 class CountFromBy(object): def __init__(self, val=0, incr=1): self. ...

  8. EF的学习

    今天学习了ORM中的Entity FrearmeWork框架,其实之前看到orm框架,感觉好高大上啊,还没准备去了解它那,今天我们就学习了这个,其实Entity FrearmeWork框架和Nhibe ...

  9. Cent OS 常用命令搜集

    打开一个 Shadowsocks 配置文件nano /etc/shadowsocks.json 重启 Shadowsocks/etc/init.d/shadowsocks restart centos ...

  10. Linux学习(二)

    Linux进程管理 每个 Linux 命令都与系统中的程序对应,输入命令,Linux 就会创建一个新的进程.例如使用 ls 命令遍历目录中的文件时,就创建了一个进程.简而言之,进程就是程序的实例. 创 ...