HDU 6335 Problem D. Nothing is Impossible

 

题意:

就是n个人考试,试卷上有m个题,每个题告诉你正确答案s和错误答案t的数量(都>=1),这n个人很团结,选取最优策略,

保证他们当中一定可以有人答对最多S题

 

思路:

注意:一定 和 最多

每一题答对的可能性为 s/(s+t)。所以s+t个人就可以答对s题

我们只需要用最少的人数答对这一题 那就是t+1个人,一定可以答对1题

所以每道题需要t+1个人才能答对

那么前i个题答对 需要 (t1+1)*(t2+1)*...*(ti+1)个人

所以如果想要更少的人答对更多的题,那么肯定先答 错误答案数量少的,所以把题目按错误数量从小到大排序,

最后只需要判断一下哪一个i会大于人数就行

 

贡献出了一道题 开心QAQ

 

 

#include <cstdio>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>
#include <iostream>
#define ll long long
#define INF 0x3f3f3f
using namespace std;
const int N=1000+100;
long long a[N],b[N];

struct node
{
    ll x,y;
}p[N];

bool cmp(node a,node b)
{
    return a.y<b.y;
}
int main()
{
    int t,n,cnt,i,id;
    long long m;
    long long ans;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%lld",&n,&m);
        for(i=1;i<=n;i++)
        {
            scanf("%lld%lld",&p[i].x,&p[i].y);
        }
        sort(p+1,p+1+n,cmp);
        ans=1;
        cnt=0;
        id=1;
        while(1)
        {
            if(id>n) break;
            ans=(ll)ans*(ll)(p[id].y+1);
            if(ans>m) break;
            cnt++;
            id++;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值