HDU-2015(偶数求和)
来源:互联网 发布:openssh windows 编辑:程序博客网 时间:2024/06/05 05:02
偶数求和
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 94183 Accepted Submission(s): 39541
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
一开始没有考虑到 m=n的情况,所以出现了Runtime Error (INTEGER_DIVIDE_BY_ZERO)的错误提示,除数为零。
#include<stdio.h>int main (){ int m,n,h,i,j,a[100],sum; while(scanf("%d",&n)!=EOF){ scanf("%d",&m); if(m==0)break; j=0; for(h=2,i=0;i<100;i++,h+=2)a[i]=h; for(i=0;i<n;i+=m){ sum=0; if(n==m){printf("%d\n",a[n/2]);j=1;break;} for(h=i;h<i+m;h++)sum+=a[h]; if(i==0)printf("%d",sum/m); else printf(" %d",sum/m); if((i+2*m)>=n){ sum=0; for(h=i+m;h<n;h++)sum+=a[h]; printf(" %d\n",sum/(n-i-m)); j=1; break; } } if(j!=1)printf("\n"); } return 0;}
阅读全文
0 0
- hdu 2015 偶数求和
- hdu 2015 偶数求和
- HDU 2015 偶数求和
- HDU 2015 偶数求和
- hdu 2015 偶数求和
- HDU 2015 - 偶数求和
- HDU 2015 偶数求和
- HDU --- 2015 偶数求和
- [hdu 2015] 偶数求和
- HDU 2015 偶数求和
- hdu 2015 偶数求和
- hdu 2015 偶数求和
- HDU 2015 偶数求和
- hdu 2015 偶数求和
- hdu 2015 偶数求和
- HDU 2015 偶数求和
- Hdu 2015 偶数求和
- hdu 2015 偶数求和
- mongo抛出异常:com.mongodb.MongoException: Lock not granted. Try restarting the transaction 解决方式
- 大数据架构中使用JSON-RPC好,还是RESTful API好?
- Shrio的域-————Realm,安全数据的保存地方。
- Retrofit单例封装工具类
- Android常见异常处理
- HDU-2015(偶数求和)
- 前端框架angular学习笔记(三)
- python split()
- 2017年10月英语总结
- 常用快捷键
- python爬虫-豆瓣数据爬取-正则匹配
- Noip 2016 换教室
- 匡斌带你飞 专题一 棋盘问题
- 第五章 SpringCloud 使用Feign调用服务