http://acm.hdu.edu.cn/showproblem.php?pid=2015
偶数求和
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 77567 Accepted Submission(s): 33033
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
AC CODE:补题:2016年10月30日14:33:35
#include<stdio.h>
#include<cstring>
#include<algorithm>
#define HardBoy main()
#define ForMyLove return 0;
using namespace std;
const int MYDD = 1103;
int HardBoy {
int n, m;
while(scanf("%d %d", &n, &m) != EOF) {
int cnt = n/m;
int a1 = 2, aj = a1+2*(m-1), ans[MYDD];
for(int j = 1; j <= cnt; j++) {
if(j == 1) a1 = 2;
else a1 = aj+2;
aj = a1+2*(m-1);
ans[j] = (a1+aj)/2;
}
int yu = n-cnt*m;
if(yu) {// n%m != 0
a1= aj+2;
aj = a1 + 2*(yu-1);
cnt++;
ans[cnt] = (a1+aj)/2;
}
for(int j = 1; j < cnt; j++)
printf("%d ", ans[j]);
printf("%d\n", ans[cnt]);
}
ForMyLove
}