2 条题解

  • 2
    @ 2023-9-24 15:23:39

    其实这题很简单,只要用sort排一下,在把1到x之间的数清零,n到n - x + 1之间的数也清零,最后累计求和,计算总分除以剩余人数,就能求出平均成绩啦

    #include <bits/stdc++.h>
    using namespace std;
    int n, a[10005], x;
    int main()
    {
    	double ans = 0;
    	cin >> n >> x;
    	for (int i = 1; i <= n; i++)
    		cin >> a[i];
    	sort(a + 1, a + n + 1);
    	for (int i = 1; i <= x; i++)
    		a[i] = 0;
    	for (int i = n; i > n - x; i--)
    		a[i] = 0;
    	for (int i = 1; i <= n; i++)
    		ans += a[i];
    	cout << fixed << setprecision(1) << ans / (n * 1.0 - x * 2.0);
    	return 0;
    }
    
    • 0
      @ 2023-1-21 17:01:24
      #include<bits/stdc++.h>
      using namespace std;
      int main()
      {
      	int i, j, x, n, sum = 0, a[10010];
      	cin >> n >> x;
      	for(i = 1; i <= n; i++)
      		cin >> a[i];
      	for(i = 1; i <= n; i++)
      		for(j = 1; j <= n-i; j++)
      			if(a[j] > a[j+1])
      				swap(a[j],a[j+1]);
      	for(i = x+1; i <= n-x; i++)
      		sum += a[i];
      	cout << fixed << setprecision(1)<<(sum*1.0)/(n-x*2)<< endl;
      	return 0;
      }
      
      
      
      • 1

      【入门】去掉x个最高最低分后的平均分

      信息

      ID
      470
      时间
      1000ms
      内存
      64MiB
      难度
      2
      标签
      递交数
      24
      已通过
      23
      上传者