题目描述

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. redis配置文件相关

    1. 默认情况下,redis不是在后台运行的,如果需要在后台运行,把该项的值更改为yes daemonize no 2. 当Redis在后台运行时,Redis默认会把pid写入/var/run/red ...

  2. 【java】 java SPI

    SPI(Service provider interface)是旨在由第三方实现或扩展的API.它可以用于启用框架扩展和可替换组件. 服务是一组众所周知的接口或(通常是抽象的)类.服务提供者是服务的特 ...

  3. [RN] 01 - Init: Try a little bit of React Native

    Ref: React Native跨平台移动应用开发 后记:这本书博客味有点浓. 本篇涉及新建工程的若干套路,以及一点语法知识. 创建新工程 (1) 解决的一大核心问题: (2) 使用Javascri ...

  4. instsrv.exe srvany.exe启动服务

    1.通过注册表注册服务 private static readonly string regpath = @"SYSTEM\CurrentControlSet\Services\Consul ...

  5. 九度 1482:玛雅人的密码(BFS)

    题目描述: 玛雅人有一种密码,如果字符串中出现连续的2012四个数字就能解开密码.给一个长度为N的字符串,(2=<N<=13)该字符串中只含有0,1,2三种数字,问这个字符串要移位几次才能 ...

  6. Empire安装和试用

    Empire2.0,powershell后渗透利器的安装和试用 https://www.restkhz.com/2017/05/empire-test/ 使用Empire“探索”Windows个人电脑 ...

  7. Spring系列之访问数据库

    一.概述 Spring的数据访问层是以统一的数据访问异常层体系为核心,结合JDBC API的最佳实践和统一集成各种ORM方案,完成Java平台的数据访问. 二.JDBC API的最佳实践 Spring ...

  8. 转:ANDROID音频系统散记之四:4.0音频系统HAL初探

    昨天(2011-11-15)发布了Android4.0的源码,今天download下来,开始挺进4.0时代.简单看了一下,发现音频系统方面与2.3的有较多地方不同,下面逐一描述. 一.代码模块位置 1 ...

  9. Delphi之Code Explorer

    Code Explorer(代码浏览器)是Delphi IDE的特性之一,它大受用户的欢迎.正如其名所表示,Code Explorer用于快速浏览源代码单元.Code Explorer通常位于Code ...

  10. Linux 下如何安装 .bin 文件

    拿到 .bin 文件,在文件所在目录下执行如下命令即可安装, ./your-file-name.bin 如果提示 “没有那个文件或目录” ,给它加上执行权限即可,执行如下命令, chmod +x ./ ...