topic
Random sub-sub
G City had a singing contest, in general, the players over and over, the judges scoring, remove the top, remove the lowest, and the rest take the average score is the final score of the player.
However, all n mind judges today are out of the question. They only from a given set of moderate probability of not being a selected fraction in front of the judges scored points played.
Given a set of n and the score, the score of a player seeking a desired value.
Input Format
The first row is the two numbers n and m, the number of judges and the size fraction represents the set of
The second line is a fraction of m digital denotes the collection of each fraction A I , guaranteed A I pairwise disjoint.
Output Format
Total output line, the player's score is desirable, to five decimal places.
SAMPLE INPUT
3 4
1 2 3 4
Sample Output
2.50000
Sample interpretation
The judges scoring four possibilities:
[2,3] is the score of the player 2
[2,4] is the score of the player 2
[1,3,4] Players score of 3
[2,3,4] Players score of 3
data range
Before 20% of the data, n <= 10
All data,. 3 <= n-<= m <= 7000, A I <= 10000
Mentality:
Because for too long not to fight codes, see the topic think the whole arrangement. . Glorious ignore the data range. . Found that only twenty. .
Yeah, that's the first two points
Autistic (Who would have thought that it is the number of channels on it) (I know only good I think)
Ideas:
By analysis of (m number of programs selected number n) and frequency calculating weights for each column in the number of occurrences of the number of re embodiment, each weighting number * / Program Number / m-2 is the answer
analysis:
(I really do not play a mathematical formula, drawing see)
Then the problem is transformed into how to calculate the general formula
Here can own i = 1, i = 2, i = 3 ...... Looking substituting law (big brother may find general rule from between i and i-1)
Then you will be able to find a recursive (pleasant)
The process of pushing yourself to think ah! (Answer on the back of the code)
Now that the law has been introduced in addition to the constant part of the front part of the demand that it should be how?
Code:
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> using namespace std; int n,k,i,j; int a[7777]; double f[7777]; int c_nk,c_n1; int main () { freopen("random.in","r",stdin); freopen("random.out","w",stdout); scanf("%d%d",&k,&n); for (i=1;i<=n;i++) scanf("%d",a+i); sort(a+1,a+1+n); f[n]=1.0; c_nk = n- k; c_n1=n-1; for (i=n;i>=k;i--) { f[i-1]=f[i]*c_nk/c_n1; c_nk--; c_n1--; } for (i=1,j=n;i<=j;i++,j--) { f[i]=f[i]+f[j]; f[j]=f[i]; } double sum=0; for (i=1;i<=n;i++) sum=sum-f[i]*a[i]; for (i=1;i<=n;i++) sum=sum+a[i]; sum/=1.0*(k-2)*n/k; printf("%.5lf\n",sum+1e-8); return 0; }
(Here a direct reference to the teacher's standard process)
Here is the answer to the above-thinking
That's it!
Fireworks put it? (laugh)