设自己会选x这个数,那么x就要成为幸运数。
所以可得方程:((sum+x)/n) * (2/3) = x
经过化简,x=2*sum/ (3*n-2)
还需要统计一下和x相同大小数字的个数。
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<deque>
#include<functional>
#include<iterator>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<sstream>
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
int dx[]= {0,1,1,1,0,-1,-1,-1};
int dy[]= {1,1,0,-1,-1,-1,0,1};
int gcd (const LL &a, const LL &b) {return b==0?a:gcd (b,a%b);}
using namespace std;
int c[105];
int main() {
int T,x;
scanf ("%d",&T);
while (T--) {
int sum=0;
memset (c,0,sizeof (c) );
int n; scanf ("%d",&n);
for (int i=1; i<n; i++) {
scanf ("%d",&x);
c[x]++; sum+=x;
}
x=2*sum/ (3*n-2);//hua jian
printf ("%d %.2f\n",x,1.0/ (c[x]+1) );
}
return 0;
}