ACM HDU 2015

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ACM HDU 2015相关的知识,希望对你有一定的参考价值。

偶数求和

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 91317    Accepted Submission(s): 38494


Problem Description
有一个长度为n(n<=100)的数列,该数列定义为从2开始的递增有序偶数,现在要求你按照顺序每m个数求出一个平均值,如果最后不足m个,则以实际数量求平均值。编程输出该平均值序列。
 

 

Input
输入数据有多组,每组占一行,包含两个正整数n和m,n和m的含义如上所述。
 

 

Output
对于每组输入数据,输出一个平均值序列,每组输出占一行。
 

 

Sample Input
3 2
4 2
 

 

Sample Output
3 6
3 7
 

 

Author
lcy
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:  2010 2016 2017 2018 2019 
两种方法:
1:按正常思路来
#include <stdio.h>
int main()
{
    int n, m, i, sum, num, num2, j, s,s1;
    while (scanf_s("%d%d", &n, &m) != EOF)
    {
        sum = 0;
        int a[10001];
        s1=num = n / m;
        s = num2 = n%m;
        j = 0;
        for (i = 2; i <= n * 2; i += 2, j++)
            a[j] = i;
        j = 0;
        while (num--)
        {
            for (i = 0; i < m; i++)
            {
                sum += a[j];
                j++;
            }
            printf("%d", sum / m);
            if (num>0)
                printf(" ");
            sum = 0;
        }
        if (num2 == 0)
            printf("\n");
        else
        {
            while (num2--)
            {
                sum += a[j];
                j++;
            }
            if (sum != 0 && s == 0)
                printf(" %d\n", sum / (s + 1));
            if (sum != 0 && s != 0)
                printf(" %d\n", sum / s);
        }
    }
    return 0;
}
2:简单很多,主要我也不知道我咋想到的!!!
#include <stdio.h>
int main(void)
{
    int a, i, n, m, b, s;
    while (scanf("%d %d", &n, &m) != EOF && n<=100)
    {
        a = 2;
        b = n%m;
        s = n / m;
        for (i = 0; i < s; i++)
        {
            printf("%d", a + m - 1);
            if (i < s - 1)
                printf(" ");
            a = a + m * 2;
        }
        if (b != 0)
        {
            printf(" %d", a);
        }
        printf("\n");
    }
    return 0;
}

以上是关于ACM HDU 2015的主要内容,如果未能解决你的问题,请参考以下文章

2015 ACM/ICPC Asia Regional Changchun Online HDU - 5441 (离线+并查集)

线段树HDU 5493 Queue (2015 ACM/ICPC Asia Regional Hefei Online)

贪心模拟HDU 5491 The Next (2015 ACM/ICPC Asia Regional Hefei Online)

ACM 2015年上海区域赛A题 HDU 5572An Easy Physics Problem

动态规划HDU 5492 Find a path (2015 ACM/ICPC Asia Regional Hefei Online)

二分最长上升子序列HDU 5489 Removed Interval (2015 ACM/ICPC Asia Regional Hefei Online)