Topic Portal
Analysis: The title requires a minimum average waiting time for all, in other words, find the shortest waiting time, then wait for it to get water time as short as possible, then let that person then water then water time as short as possible
Greedy strategy: let people access the water a short time before-the water
#include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; struct node { int num; int data; }; node person[1005]; int n; long long sum; double ans; inline bool cmp(node x,node y) { if(x.data==y.data) return x.num<y.num; return x.data<y.data; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&person[i].data); person[i].num=i; } sort(person+1,person+n+1,cmp); for(int i=1;i<=n-1;i++) sum+=person[i].data*(n-i); for(int i=1;i<=n;i++) printf("%d ",person[i].num); printf("\n"); printf("%.2lf",1.0*sum/n); return 0; }