Test instructions: There are n individuals to participate in the competition, give n-1 personal results, and then to choose a lucky person, first of all the scores for the average, and then *2/3, that is not more than this number, and the closest number, is the most fortunate,
Let you set the last person's points, so that he is the luckiest.
Analysis: The topic said, up to 100, so little, completely can be violent ah, and then constantly update the maximum probability.
The code is as follows:
#include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream > #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector > #include <map>using namespace std; typedef long Long Ll;typedef pair<int, int> p;const int INF = 0x3f3f3f3 F;const Double inf = 0x3f3f3f3f3f3f3f;const double EPS = 1e-8;const int maxn = + 5;const int dr[] = {0, 0,-1, 1};cons t int dc[] = {-1, 1, 0, 0};char s[maxn][maxn];int N, m;int vis[maxn][maxn];inline bool is_in (int r, int c) {return R &G t;= 0 && R < n && C >= 0 && C < m;} int A[maxn];int Main () {int T; cin >> T; while (t--) {scanf ("%d", &n); int sum = 0; for (int i = 1; i < n; ++i) {scanf ("%d", &a[i]); Sum + = A[i]; } sort (a+1, a+n); int indx = 1000; Double ans = 0.0; int p =-1; for (int i = 0; i <= 100; ++i) {Double T = sum*1.0 + i*1.0; t = T * 2.0/3.0/(n*1.0); int tt = (int) T; if (i > TT) continue; bool OK = true; int cnt = 0; for (int j = n-1; j > 0;--j) {if (A[j] <= tt && A[J] > i) {ok = false; Break } else if (a[j] = = i) ++cnt; else if (A[j] < i) break; } if (!ok) continue; if (indx >= cnt) {indx = cnt; p = i; }} printf ("%d%.2lf\n", p, 1.0/(indx+1) *1.0); } return 0;}
HDU 5074 Luck Competition (violence, probability)