• <input id="auww4"></input>
  • <input id="auww4"><acronym id="auww4"></acronym></input>
  • <input id="auww4"><u id="auww4"></u></input>
    <object id="auww4"><acronym id="auww4"></acronym></object>
    <menu id="auww4"></menu><input id="auww4"><u id="auww4"></u></input>
    <input id="auww4"><u id="auww4"></u></input>
  • F.A.Q
    Hand In Hand
    Online Acmers
    Forum | Discuss
    Statistical Charts
    Problem Archive
    Realtime Judge Status
    Authors Ranklist
     
         C/C++/Java Exams     
    ACM Steps
    Go to Job
    Contest LiveCast
    ICPC@China
    Best Coder beta
    VIP | STD Contests
    Virtual Contests
        DIY | Web-DIY beta
    Recent Contests
    Author ID 
    Password 
     Register new ID

    Re:10行C代碼,超簡單

    Posted by 18-大數據-杜廣華 at 2019-03-23 12:50:02 on Problem 2015
    (392)  


    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        int n,m,i,j,ave;  //n是數列元素個數,m是每隔多少元素算平均值。
        while(scanf("%d%d",&n,&m)!=EOF)
        {
            j=0;
            if(n%m==0)
            {
                for(i=1; i<=n; i++)
                {
                    j=i*i+i;
                    if(i%m==0)
                    {
                        j-=(i-m)*(i-m)+i-m;
                        ave=j/m;
                        if(i/m==1)
                            printf("%d",ave);
                        else
                            printf(" %d",ave);
                    }
                }
            }
            else
            {
                for(i=1; i<=n-n%m; i++)
                {
                    j=i*i+i;
                    if(i%m==0)
                    {
                        j-=(i-m)*(i-m)+i-m;
                        ave=j/m;
                        printf("%d ",ave);
                    }
                }
                printf("%d",(n*n+n-(i-1)*(i-1)-i+1)/(n%m));
            }
            printf("\n");
        }
    }

    Followed by:


    Post your reply here:

    Author ID
    Password
    Title
    Content  
     
    Hangzhou Dianzi University Online Judge 3.0
    Copyright © 2005-2021 HDU ACM Team. All Rights Reserved.
    Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
    Total 0.015600(s) query 5, Server time : 2021-01-21 09:30:52, Gzip enabled
    棋牌