zoukankan      html  css  js  c++  java
  • HUSTM 1601

    题目描述
    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
    ",ans);
                    continue;
                }
                else
                {
                    for(int j=b;j<=n;j+=c)
                        ans+=a[j];
                }
                printf("%lld
    ",ans);
    
            }
        }
        return 0;
    }
  • 相关阅读:
    [Unity菜鸟] 协程Coroutine
    [Unity菜鸟] Unity发布web后,从HTML调用本地文件
    [Unity菜鸟] Unity鼠标双击,鼠标函数整理(未完)
    [Unity菜鸟] Unity Web Player 相关问题 (待完善)
    [Unity菜鸟] Unity读XML
    [Unity菜鸟] 术语
    [Unity菜鸟] 笔记2 —— 问题篇
    [Unity菜鸟] Mecanim 系统遇到的问题
    学习:条件[记录]断点
    学习:硬件断点
  • 原文地址:https://www.cnblogs.com/dacc123/p/8228779.html
Copyright © 2011-2022 走看看