求助,不用结构体的方法,用注释里的替换上一行就会wa
查看原帖
求助,不用结构体的方法,用注释里的替换上一行就会wa
393223
Xleprime楼主2021/1/23 00:32

//感觉注释里的代码更对啊

#include <cstdio>
#include <algorithm>
#include <cstdlib>
#define ll long long
using namespace std;

int main()
{
    ll n, x;
    ll a[1005];
    double sum = 0;
    double ans;
    scanf("%lld", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%lld", &x);
        a[i] = x * 1005 + i; //!!
    }

    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i)
    {
        printf("%lld ", a[i] % 1005);
        sum += a[i] / 1005 * (n - i);
        //sum += (a[i] - i) / 1005 * (n - i);
    }
    printf("\n");
    ans = (double)sum / n;
    printf("%.2lf", ans);
    system("pause");
    return 0;
}
2021/1/23 00:32
加载中...