洛谷 分类平均 P5719

洛谷 分类平均 P5719_第1张图片

#include
using namespace std;
int main(){
	int n;
	int k;
	cin >> n >> k;
	double A[10000] = {0};
	double B[10000] = {0};
	int a = 0;
	int b = 0;
	for(int i = 1;i <= n;i++){
		if (i % k == 0){
			A[a++] = i;
		} 
		else {
			B[b++] = i;
		}
	}
	double sum_a = 0;
	for (int i = 0;i < a;i++){
		sum_a = sum_a + A[i];
	}
	double sum_b = 0; 
	for (int i = 0;i < b;i++){
		sum_b = sum_b + B[i];
	}
	
	double ra= sum_a / a;
	double rb= sum_b / b;
	cout << fixed<<setprecision(1)<<ra<<' '<<rb;
	return 0; 
}

你可能感兴趣的:(C++,学习,c++)