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

C语言程序设计练习(三)

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;
}
时间: 2024-10-12 04:03:55

ACM HDU 2015的相关文章

[ACM] hdu 1242 Rescue (BFS+优先队列)

Rescue Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison. Angel's friends want to save Angel. Their task is:

[ACM] hdu 2089 不要62(数位Dp)

不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 19043    Accepted Submission(s): 6442 Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer). 杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就

[ACM] hdu 1253 胜利大逃亡 (三维BFS)

胜利大逃亡 Problem Description Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会. 魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,现在知道魔王将在T分钟后回到城堡,Ignatius每分钟能从一个坐标走到相邻的六个坐标中的其中一个.现在给你城堡的地图,请你计算出Ignatius能否在魔王回来前离开城堡(只要走到出

[ACM] hdu 1285 确定比赛名次 (拓扑排序)

确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10358    Accepted Submission(s): 4046 Problem Description 有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直

[ACM] hdu 1231 最大连续子序列 (动规复习)

最大连续子序列 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17687    Accepted Submission(s): 7828 Problem Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j

[ACM] hdu 1260 Tickets (动态规划)

Tickets Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 4   Accepted Submission(s) : 2 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Jesus, what a great movie! Thou

[ACM] hdu 1242 【BFS】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1242 参考链接:http://www.acmerblog.com/hdu-1242-Rescue-1605.html 普通队列+bfs确实是蒙对的,因为击败守卫需要消耗时间1,因此普通队列每一次出队列的元素只是步数上最优,但不一定是时间上最优的,这时即使我们把整个迷宫搜完以最小值为最优依然不行,因为每一步处理完成都会把该状态标记为已处理vis[i][j]=1,因此,只要有一步不是最优,就会影响后面的

[ACM] hdu 3555 Bomb (数位DP,统计1-N中含有“49”的总数)

Bomb Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 7187 Accepted Submission(s): 2512 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists impro

HDU 2015 偶数求和

本题一开始我想用数组将数存起来,但想了好久就是没思路写下去,最后参考了人家的代码,写的挺不错的,和大家分享一下 偶数求和 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 45013    Accepted Submission(s): 19665 Problem Description 有一个长度为n(n<=100)的数列,该数列定义为