HDU 5074 Luck Competition (violence, probability)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.