偶数求和

偶数求和

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 88210    Accepted Submission(s): 37175


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
lcy   |   We have carefully selected several similar problems for you:   1096  1001  1000  1093  1089 
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<cstdlib>
#include <set>
#include<algorithm>
#include <limits.h>
#include <ctype.h>
#include <map>
#include <stack>
typedef long long LL;
using namespace std;
const int N = 105;
int data[N][N];
int dp[N][N];
int f[35];
char c[6] = {'A', 'B', 'C', 'D', 'E', 'F'};
float obj[5];
void fun(int n, int m)
{
    int flag = 0;
    if(n < 0){
        flag = 1;
        n = -n;
    }
    stack<char> s1;
    while(n != 0){
        int yushu = n % m;
        if(yushu >= 10){
            s1.push(c[yushu - 10]);
        }else {
            s1.push(yushu + '0');
        }
        n =  n / m;
    }
    if(flag){
        cout << "-";
    }
    while(!s1.empty()){
        cout << s1.top();
        s1.pop();
    }
    cout << endl;
}
int gcd(int a, int b)
{
    return b == 0 ? a : gcd(b, a % b);
}
int lcm(int a, int b)
{
    return a  / gcd(a, b) * b;
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
//    int n, sum;
//    while(scanf("%d %d", &n, &sum) != EOF){
//        if(n == 0 && sum == 0) break;
//        for(int i = 1; i <= n; i++){
//            int T = 0;
//            for(int j = i; j <= n; j++){
//                T += j;
//                if(T == sum ){
//                    cout << "["<< i << "," << j <<"]"<< endl;
//                    break;
//                }else if(T < sum){
//                    continue;
//                }else {
//                    break;
//                }
//            }
//        }
//        cout << endl;
//    }
    int n, m;
    while(scanf("%d %d", &n,&m) != EOF){
        int k =  n / m;
        int ans = 0, temp = 2;
        for(int i = 0; i < k; i++){
            int ans = 0;
            for(int j = 0; j < m; j++){
                ans += temp;
                temp += 2;
            }
            if(i == 0)
                cout << ans / m;
            else {
                cout << " "<< ans / m ;
            }
        }
        ans = 0;
        if(n % m != 0){
            for(int i = 0; i < n % m; i++){
                ans += temp;
                temp += 2;
            }
            cout << " " <<ans / (n % m);
        }
        cout << endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值