1050:偶数求和
来源:互联网 发布:网络格言 编辑:程序博客网 时间:2024/06/05 07:08
1050:偶数求和
Description
有一个长度为n(n<=100)的数列,该数列定义为从2开始的递增有序偶数(公差为2的等差数列),现在要求你按照顺序每m个数求出一个平均值,如果最后不足m个,则以实际数量求平均值。编程输出该平均值序列。
Input
输入数据有多组,每组占一行,包含两个正整数n和m,n和m的含义如上所述。
Output
对于每组输入数据,输出一个平均值序列,每组输出占一行
Sample Input
3 2
4 2
Sample Output
3 6
3 7
#include<iostream>#include<string>using namespace std;int main(){ int n,m; while(cin>>n>>m) { int i=0,index=0,k,j=0,count,shabi, sibi=m; shabi=n%m; int a[102],b[100]={0}; a[0]=2; for(int i=1;i<=n;i++) a[i]=a[i-1]+2; count=n-m; while(count>=0) { for(k=index;k<index+m;k++) b[j]=b[j]+a[k]; b[j]=b[j]/sibi; n=n-m; j++; index=index+m; count=n-m; } if(n>0) { for(int i=k;i<k+n;i++) b[j]=b[j]+a[i]; b[j]=b[j]/n; } cout<<b[0]; if(n%m==0) { for(int c=1;c<j;c++) cout<<" "<<b[c]; } else { for(int c=1;c<=j;c++) cout<<" "<<b[c]; } cout<<endl;}return 0;}
阅读全文
0 0
- 1050: 【偶数求和】
- 1050:偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- 偶数求和
- Oculus Home安装
- python requests
- Git fetch和git pull的区别, 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists).
- poj 2823 Sliding Window(单调队列)
- 反射
- 1050:偶数求和
- 【React Native】ES6新特性
- 隐写术总结
- 删除或修改本地Git账号密码
- 2018招商银行笔试题——团建活动
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
- Cocos2d-lua 初识shader之一:置灰
- easyPoi学习
- jquery 数据校验,input只能输入浮点数