A. Queue for water
Time limit:3000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Description
Every two floors of each bedroom in our school is a hot place, so how to reduce the water time is an interesting question. Suppose there are n people in the front row of a faucet to connect water, if everyone to water time for TI, please program to find out the order of this n individual queue, so that the average waiting time for n people minimum.
Input
There are multiple sets of input data.
Each set of data is two rows, the first behaves an integer n (1£n£100000), which represents the number of people queued. The second row of n integers, ti (1£ti£1000), represents the time each person takes to get water.
Output
For each set of data, the output takes up two lines. The first behavior is a queueing order, that is, a 1 to n arrangement, a space between each number, if the answer has more than one, the output dictionary order of the smallest sequence (that is, when the time is the same as the first occurrence of the first ordinal output); Second behavior The average wait time under this arrangement (the output is accurate to two decimal places)
Sample Input
4
2 3 3 1
10
56 12 1 99 1000 234 33 55 99 812
Sample Output
4 1 2 3
2.50
3 2 7 8 1 4 9 6 10 5
291.90
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int n;
struct Node
{
int t,num;
} NODE[100000];
BOOL CMP (struct node a,struct Node B)
{
return a.t<=b.t;
}
int main ()
{
while (~scanf ("%d", &n))
{
memset (node,0,sizeof (Node));
for (int i=1; i<=n; i++)
{
scanf ("%d", &node[i].t);
node[i].num=i;
}
Sort (node+1,node+n+1,cmp);
for (int i=1; i<=n; i++)
printf ("%d", node[i].num);
printf ("\ n");
Double sum=0,s=0;
for (int i=1; i<=n; i++)
{
sum+=s;
s+=node[i].t;
}
printf ("%.2lf\n", sum/n);
}
return 0;
}