首页 > 其他分享 >HUST 1601 Shepherd

HUST 1601 Shepherd

时间:2022-11-09 18:40:06浏览次数:40  
标签:sheep Shepherd weight 1601 HUST int each integer he


Description



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. 


Input



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-thsheep. 
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. 


Output



For each plan (the same order in the input), print the total weight of sheep selected. 


Sample Input



5 1 2 3 4 5 3 1 1 2 2 3 3


Sample Output



15 6

3

可以先预处理出间隔为1到60的前缀和,然后超过60的暴力就好了,本来这题应该是离线nsqrt(n)的,然而数据太水了,而且数据也是错的,明明说了b>=1,结果竟然有0的,暴力也能跑的过去,只能说数据太有问题了

#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e5+10;
int n,m,a[maxn],x,y;
LL sum[maxn][61];

int main()
{
while (~scanf("%d",&n))
{
for (int i=1;i<=n;i++) scanf("%d",&a[i]);
int k=min(60,n);
for (int i=n;i>=1;i--)
{
for (int j=1;j<=k;j++)
{
if (i+j<=n) sum[i][j]=sum[i+j][j]+a[i];
else sum[i][j]=a[i];
}
}
scanf("%d",&m);
while (m--)
{
scanf("%d%d",&x,&y);
if (y>k)
{
LL ans=0;
for (int i=x;i<=n;i+=y) ans+=a[i];
printf("%lld\n",ans);
}
else if (y) printf("%lld\n",sum[x][y]);
else printf("%d\n",a[x]);
}
}
return 0;
}



标签:sheep,Shepherd,weight,1601,HUST,int,each,integer,he
From: https://blog.51cto.com/u_15870896/5837708

相关文章

  • HUST 1606 Naive
    DescriptionGiveyouapositiveintegerx,determinewhetheritisthesumofthreepositivecubicnumbers.InputThere’reseveraltestcases.Fo......
  • HUST 1602 Substring
    DescriptionThisproblemisquieteasy. Initially,thereisastringA.   Thenwedothefollowingprocessinfinitytimes.  A:=A+......
  • HUST 1599 Multiple
    DescriptionRocket323 lovesmathverymuch.Oneday, Rocket323 gotanumberstring.Hecouldchoosesomeconsecutivedigitsfromthestringtoform......
  • HUST 1600 Lucky Numbers
    DescriptionIsun lovesdigit4and8verymuch.Hethinksanumberisluckyonlyifthenumbersatisfythefollowingconditions: 1.      The......
  • 数据库启动时报警 ORA-03113 ORA-16014 ORA-00312
    系统:CentOS7.9数据库:oracle11.2.0.4问题描述:数据库启动时报警ORA-03113,如下所示:SQL>startupORACLEinstancestarted.TotalSystemGlobalArea2455228416bytesFixedS......
  • CF1601C Optimal Insertion 解题报告
    确实是一道好题模拟赛打挂了题意给定两个序列\(a,b\),长度分别为\(n,m(1\leqn,m\leq10^6)\))。接下来将\(b\)中的所有元素以任意方式插入序列\(a\)中任意位置,请......
  • CodeForces-1601B Frog Traveler
    FrogTravelerdp+bfs感觉又像搜索从后往前进行状态转移,像\(bfs\)一样保证当前搜索的是消耗次数最少的状态转移因为是一个连续的区间,因此考虑当前能上升到的最大距......