【2016杭电女生赛1003】【暴力】Luck Competition 选数平均数乘2除3 小且最接近的数

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
#include<assert.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int casenum, casei;
int n, x;
int cnt[105];
int main()
{
    scanf("%d", &casenum);
    for (casei = 1; casei <= casenum; ++casei)
    {
        MS(cnt, 0);
        scanf("%d", &n);
        int sum = 0;
        for (int i = 1; i < n; ++i)
        {
            scanf("%d", &x);
            sum += x;
            ++cnt[x];
        }
        for (int i = 100; i >= 0; --i)cnt[i] += cnt[i + 1];
        int ans = -1;
        int num = 10000;
        for (int i = 0; i <= 100; ++i)
        {
            int m = (sum + i) * 2 / (3 * n);

            //如果i是比m小的最大的数则尝试更新答案
            if (i <= m && (i + 1 > m || cnt[i + 1] == 0))
            {
                if (cnt[i] - cnt[i+1] <= num)
                {
                    ans = i;
                    num = cnt[i] - cnt[i+1];
                }
            }
        }
        printf("%d %.2f\n", ans, 1.0 / (1 + num));
    }
    return 0;
}
/*
【题意】
n(2~100)个人参加一个游戏,
每个人选择1~100范围的数。
然后得到所有数的平均数,再*=2/3,设得到的数为m。
如果一个人选的数,比m小,且相距m最为接近,那么其便在所有选数相同的人中等概率中奖。

现在,我们也参加比赛,其他n-1个人所选择的数也已经确定了,并且我们知道。
问你,选什么数拥有最高中奖率,并输出。

【类型】
暴力

【分析】
这题选数范围非常小,只有1~100。
于是我们可以直接暴力枚举这个人选的数是什么,
然后,我们便可以算出这个m。
m可以为浮点数或者向下取整变为int,这个是怎样都不影响,于是我们不妨取m为整数。

接下来,如果这个数,是<=m的数中最大的数,我们便可以在这个基础上更新答案。
如果用一个后缀和优化的话,复杂度就由O(100nT)变为O(100T)

【时间复杂度&&优化】
O(100nT)->O(100T)

*/


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值