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 ...
随机推荐
- 2、一、Introduction(入门):1、Application Fundamentals(应用程序基础)
一.Introduction(入门) 1.Application Fundamentals(应用程序基础) Android apps are written in the Java programmi ...
- Resolve PSExec "Access is denied"
PSExec拒绝访问的解决办法 Just modify Windows Registry, and reboot. psexec_fix.reg: Windows Registry Editor Ve ...
- iOS开发--改变tableHeaderView的高度
1.先获取tableHeaderView 2.设置它的frame 3.将该view设置回tableview UIView *view=tableView. tableHeaderView; view. ...
- linux 下的爆破工具hydra
http://www.cnblogs.com/mchina/archive/2013/01/01/2840815.html 安装手册 http://www.aldeid.com/wiki/Thc-hy ...
- ListView实现多种item布局的方法和注意事项
这篇文章的效果也是大家常见的,各种通讯应用的对话列表都是这种方式,像微信.whatsapp.易信.米聊等.我们这篇文章也权当为回忆,形成简单的笔记.这篇文章参考了2009年Google IO中的< ...
- [C] include <filename> 和 include "filename" 的区别
在 C 语言中包含语句 #include <filename> 和 #include "filename" 的区别在于编译器的偏好,一般来说,使用双引号表示优先搜索当前 ...
- python--Anaconda学习笔记
http://study.163.com/course/courseLearn.htm?courseId=1003664056#/learn/video?lessonId=1048567028& ...
- codeforces水题100道 第十九题 Codeforces Round #109 (Div. 2) A. I_love_%username% (brute force)
题目链接:http://www.codeforces.com/problemset/problem/155/A题意:找到当前最大值或者最小值出现的次数.“当前”的意思差不多是a[i]大于所有a[j]( ...
- 八款值得尝试的精美的 Linux 发行版(2017 版)
八款值得尝试的精美的 Linux 发行版(2017 版) 2017年10月18日 • Linux • 295 views • 暂无评论 在这篇文章中,将会列出让一些令 Linux 用户印象最深刻且精美 ...
- EXCEL数据匹配:The 'Microsoft.Jet.Oledb.4.0' provider is not registered on the local machin
百度的处理结果: 作者:LisenYang http://blog.csdn.net/lisenyang/article/details/52106492 这篇博文里面说的,默认设置修改[启动32应用 ...