2 条题解

  • 0
    @ 2024-5-30 21:55:23
    #include<iostream>
    #include<iomanip>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<string>
    #include<algorithm>
    #define LL long long
    using namespace std;
    const int N=1e5+10;
    const int Inf=0x3f3f3f3f;
    int n;
    double time1 = 1.00 * 0;
    struct per {
    	int t;
    	int num;
    }a[N];
    
    bool cmp(per a, per b){
    	if(a.t==b.t){
    		return a.num<b.num;
    	}
    	return a.t < b.t;
    }
    
    int main(){
    	int n;
    	cin >> n;
    	for(int i = 1; i <= n; i++) {
    		cin >> a[i].t;
    		a[i].num = i;
    	}
    	sort(a + 1, a + n + 1, cmp);
    	int sum = n - 1;
    	for(int i = 1; i <= n; i++) {
    		time1 += 1.00 * a[i].t * sum;
    		sum--;
    		cout << a[i].num << ' ' ;
    	}
    	time1 /= 1.00 * n;
    	cout << endl;
    	printf("%.2lf", time1);
    }
    
    
    • 0
      @ 2024-3-24 15:37:19
      #include <bits/stdc++.h>
      using namespace std;
      const int N=1e5+10;
      const int INF=0x3f3f3f3f;
      int n;
      double tim = 1.00 * 0;
      struct person {
      	int t;
      	int num;
      }a[N];
      
      bool cmp(person a, person b)
      {
      	return a.t < b.t;
      }
      
      int main()
      {
      	int n;
      	cin >> n;
      	for(int i = 1; i <= n; i++) {
      		cin >> a[i].t;
      		a[i].num = i;
      	}
      	sort(a + 1, a + n + 1, cmp);
      	int sum = n - 1;
      	for(int i = 1; i <= n; i++) {
      		tim += 1.00 * a[i].t * sum;
      		sum--;
      		cout << a[i].num << ' ' ;
      	}
      	tim /= 1.00 * n;
      	cout << endl;
      	printf("%.2lf", tim);
      }
      40分
      
      • 1

      信息

      ID
      3007
      时间
      1000ms
      内存
      256MiB
      难度
      8
      标签
      递交数
      310
      已通过
      48
      上传者