1 solutions

  • 0
    @ 2022-2-18 11:04:54

    题目链接

    http://acm.mangata.ltd/p/E0761

    思路

    我们对a数组进行排序操作,然后从左往右,从右往左把重复的最小元素去掉,我们这里用的是l、r两个代表位置的指针,然后将中间的元素加起来最后除以这个区间的长度即可

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    const int N = 1e3+10;
    double a[N];
    
    int main()
    {
    	int n;
    	cin>>n;
    	for(int i = 0;i < n; ++i) cin>>a[i];
    	sort(a,a+n);
    	int l = 1,r = n - 2;
    	n -= 2;
    	while(l <= r && a[l] == a[l-1]) l++,n--;
    	while(r >= l && a[r] == a[r+1]) r--,n--;
    	double sum = 0;
    	for(;l <= r; ++l) sum += a[l];
    	cout<<sum<<endl;
    	cout<<fixed<<setprecision(1)<<sum/(n * 1.0)<<endl;
    	return 0;
    }
    
    • 1

    Information

    ID
    1061
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    1
    Tags
    # Submissions
    6
    Accepted
    6
    Uploaded By