HDU 4815 2013长春现场赛C题

C - Little Tiger vs. Deep Monkey

Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d
& %I64u

Submit Status Practice HDU
4815

Description

A crowd of little animals is visiting a mysterious laboratory ? The Deep Lab of SYSU.

“Are you surprised by the STS (speech to speech) technology of Microsoft Research and the cat face recognition project of Google and academia? Are you curious about what technology is behind those fantastic demos?” asks the director of the Deep Lab. “Deep learning,
deep learning!” Little Tiger raises his hand briskly. “Yes, clever boy, that’s deep learning (深度学习/深度神经网络)”, says the director. “However, they are only ‘a piece of cake’. I won’t tell you a top secret that our lab has invented a Deep Monkey (深猴) with more
advanced technology. And that guy is as smart as human!”

“Nani ?!” Little Tiger doubts about that as he is the smartest kid in his kindergarten; even so, he is not as smart as human, “how can a monkey be smarter than me? I will challenge him.”

To verify their research achievement, the researchers of the Deep Lab are going to host an intelligence test for Little Tiger and Deep Monkey.

The test is composed of N binary choice questions. And different questions may have different scores according to their difficulties. One can get the corresponding score for a question if he chooses the correct answer; otherwise, he gets nothing. The overall
score is counted as the sum of scores one gets from each question. The one with a larger overall score wins; tie happens when they get the same score.

Little Tiger assumes that Deep Monkey will choose the answer randomly as he doesn’t believe the monkey is smart. Now, Little Tiger is wondering “what score should I get at least so that I will not lose in the contest with probability of at least P? ”. As little
tiger is a really smart guy, he can evaluate the answer quickly.

You, Deep Monkey, can you work it out? Show your power!?/div>

Input

The first line of input contains a single integer T (1 ≤ T ≤ 10) indicating the number of test cases. Then T test cases follow.

Each test case is composed of two lines. The first line has two numbers N and P separated by a blank. N is an integer, satisfying 1 ≤ N ≤ 40. P is a floating number with at most 3 digits after the decimal point, and is in the range of [0, 1]. The second line
has N numbers separated by blanks, which are the scores of each question. The score of each questions is an integer and in the range of [1, 1000]?/div>

Output

For each test case, output only a single line with the answer.

Sample Input

 1
3 0.5
1 2 3 

Sample Output

 3 

这题逗逼了,刚开始大帝告诉我题意可能我理解错了,然后就用二进制枚举了!然后然后……然后就浪费了一个多小时一直WA,后面大帝发觉我理解错了之后,他又敲了背包才过……唉……发现题意真的是有点难理解了。到现在题意和解法还都是半知半懂的。

正确的解法是:总的情况是:1<<n,然后可组合的次数除以总的情况>=p的最小分数是正确答案。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
long long dp[40005];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,i,j,sum=0,a[45];
        double p;
        memset(dp,0,sizeof(dp));
        dp[0]=1;
        cin>>n>>p;
        for(i=0;i<n;i++)
            scanf("%d",a+i),sum+=a[i];
        sort(a,a+n);
        for(i=0;i<n;i++)
            for(j=sum;j>=a[i];j--)
                dp[j]+=dp[j-a[i]];
        long long sum1=1LL<<n,sum2=0;
        for(i=0;i<=sum;i++)
        {
            sum2+=dp[i];
            if((double)sum2/(double)sum1>=p)
            {
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}

HDU 4815 2013长春现场赛C题

时间: 2024-10-05 05:40:12

HDU 4815 2013长春现场赛C题的相关文章

hdu 4813(2013长春现场赛A题)

把一个字符串分成N个字符串 每个字符串长度为m Sample Input12 5 // n mklmbbileay Sample Outputklmbbileay 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm> 5 # include <string> 6 # include <cmath> 7 # in

hdu 5538 House Building(长春现场赛——水题)

题目链接:acm.hdu.edu.cn/showproblem.php?pid=5538 House Building Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 621    Accepted Submission(s): 398 Problem Description Have you ever played the vid

HDU 4427 Math Magic (2012年长春现场赛H题)

1.题目描述:点击打开链接 2.解题思路:本题要求寻找k个正整数,它们的和恰好是N,它们的LCM恰好是M的解的个数.可以设置一个三维的dp来解决.用dp(i,j,k)表示选择i个数,它们的和恰好是j,它们的LCM恰好是k的个数.那么答案就是dp(k,n,m).不过这里介绍一种利用状态压缩思想求解的方法. 通过题意可以发现,N,M的范围都比较小,不超过1000,而1000之内的所有数的不同素因子的种类数目不超过4个,这是因为2*3*5*7<1000,而2*3*5*7*11>1000.考虑到素因子

hdu 5078 2014鞍山现场赛 水题

http://acm.hdu.edu.cn/showproblem.php?pid=5078 现场最水的一道题 连排序都不用,因为说了ti<ti+1 //#pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include &l

hdu 5078(2014鞍山现场赛 I题)

数据 表示每次到达某个位置的坐标和时间 计算出每对相邻点之间转移的速度(两点间距离距离/相隔时间) 输出最大值 Sample Input252 1 9//t x y3 7 25 9 06 6 37 6 01011 35 6723 2 2929 58 2230 67 6936 56 9362 42 1167 73 2968 19 2172 37 8482 24 98 Sample Output9.219544457354.5893762558 1 # include <iostream> 2 #

hdu 5443 (2015长春网赛G题 求区间最值)

求区间最值,数据范围也很小,因为只会线段树,所以套了线段树模板=.= Sample Input3110011 151 2 3 4 551 21 32 43 43 531 999999 141 11 22 33 3 Sample Output1002344519999999999991 1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <algorithm>

hdu 5446(2015长春网络赛J题 Lucas定理+中国剩余定理)

题意:M=p1*p2*...pk:求C(n,m)%M,pi小于10^5,n,m,M都是小于10^18. pi为质数 M不一定是质数 所以只能用Lucas定理求k次 C(n,m)%Pi最后会得到一个同余方程组x≡B[0](mod p[0])x≡B[1](mod p[1])x≡B[2](mod p[2])......解这个同余方程组 用中国剩余定理 Sample Input19 5 23 5 Sample Output6 1 # include <iostream> 2 # include <

hdu 5442 (ACM-ICPC2015长春网络赛F题)

题意: 分析: 明天再写…… #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define d(x) const int MAX_N = (int)(4e4) + 100; //call init_RMQ(f[], n) first. //then call query(a, b) to quest the RMQ of [a, b]. int power[3

HDU 4791 Alice&#39;s Print Service(2013长沙区域赛现场赛A题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4791 解题报告:打印店提供打印纸张服务,需要收取费用,输入格式是s1 p1 s2 p2 s3 p3...表示打印区间s1到s2张纸的单价是p1,打印区间s2 到s3的单价是p2....最后是sn到无穷大的单价是pn,让你求打印k张纸的总费用最少是多少?有m次查询. 因为s1*p1 > s2 * p2 > s3*p3......,很显然,加入k所在的那个区间是第x个区间,那么最低费用要么是k * p