2013 Asia Regional Changchun C

Little Tiger vs. Deep Monkey

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 960    Accepted Submission(s): 344

Problem 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!?

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]?

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

Source

2013 Asia Regional Changchun

一开始想法是对的,但是实现起来没弄好。

用long long存种类数竟然一直wa,改成概率就AC了,应该是精度的问题,毕竟2^40太大了。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<map>
 6 #include<algorithm>
 7 #include<vector>
 8 #define M(a,b) memset(a,b,sizeof(a))
 9 #define eps 1e-6
10 using namespace std;
11
12 double p;
13 int n;
14 int num[45];
15 double dp[45][40005];
16 int cnt;
17
18 int main()
19 {
20     int t;
21     scanf("%d",&t);
22     while(t--)
23     {
24     scanf("%d%lf",&n,&p);
25     //long long a = pow(2,(long long)n);
26     for(int i = 0;i<n;i++)
27     {
28         scanf("%d",&num[i]);
29     }
30     M(dp,0);
31     dp[0][0] = 1;
32     for(int i = 0;i<n;i++)
33     {
34         for(int j = 0;j<1000*n;j++)
35             {dp[i+1][j] += dp[i][j]*0.5;
36             dp[i+1][j+num[i]]+= dp[i][j]*0.5;}
37     }
38         double res = 0;
39         int ans = 0;
40         for(int i = 1000*n;i>=0;i--)
41         {
42            res+=dp[n][i];
43            if(res>1-p) {ans = i; break;}
44         }
45         printf("%d\n",ans);
46     }
47     return 0;
48 }
49 /*
50 1
51 3 0.1
52 1 2 3
53 10
54 40 0.5
55 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
56 10
57 10 0.7
58 1 2 3 2 3 2 1 1 3 4
59 13
60
61 */

把之前wa的代码也粘上吧:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<map>
 6 #include<algorithm>
 7 #include<vector>
 8 #define M(a,b) memset(a,b,sizeof(a))
 9 #define eps 1e-6
10 using namespace std;
11
12 double p;
13 int n;
14 int num[45];
15 int cnt;
16 double m[400005];
17 double pls[400005];
18 int which[400005];
19 long long a;
20
21 int main()
22 {
23     int t;
24     scanf("%d",&t);
25     while(t--)
26     {
27     scanf("%d%lf",&n,&p);
28     a = pow(2,n);
29     for(int i = 0;i<n;i++)
30     {
31         scanf("%d",&num[i]);
32     }
33     M(m,0);
34     m[0] = 1.0/a;
35     for(int i = 0;i<n;i++)
36     {
37         int cnt = 0;
38         for(int j = 0;j<40000;j++)
39         {
40                if(m[j]>0)
41                {
42                    pls[cnt] = m[j];
43                    which[cnt] = j+num[i];
44                    cnt++;
45                }
46         }
47         for(int i = 0;i<cnt;i++)
48         {
49                m[which[i]] += pls[i];
50         }
51     }
52         double res = 0;
53         int ans = 0;
54         for(int i = 0;i<40000;i++)
55         {
56                res+=m[i];
57                if(res>=p) {ans = i; break;}
58         }
59         //cout<<a<<endl;
60         //cout<<ct<<endl;
61         printf("%d\n",ans);
62     }
63     return 0;
64 }
65 /*
66 1
67 3 0.1
68 1 2 3
69 10
70 40 0.5
71 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
72 10
73 10 0.7
74 1 2 3 2 3 2 1 1 3 4
75 13
76
77 */
时间: 2024-12-21 07:16:15

2013 Asia Regional Changchun C的相关文章

HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spherical deep-sea submersible which was unpowered and lowered into the ocean on a cable, and was used to conduct a series of dives under the sea. The Bathys

HDU 4822 Tri-war(LCA树上倍增)(2013 Asia Regional Changchun)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4822 Problem Description Three countries, Red, Yellow, and Blue are in war. The map of battlefield is a tree, which means that there are N nodes and (N – 1) edges that connect all the nodes. Each country

2013 Asia Regional Changchun

Hard Code http://acm.hdu.edu.cn/showproblem.php?pid=4813 1 #include<cstdio> 2 char op[1024]; 3 int main(){ 4 int t,n,m; 5 while(~scanf("%d",&t)){ 6 while(t--){ 7 scanf("%d%d%s",&n,&m,op); 8 for(int i=0;i<n;i++){ 9

2013 Asia Regional Changchun I 题,HDU(4821),Hash

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4821 解题报告:搞了很久,总算搞出来了,还是参考了一下网上的解法,的确很巧,和上次湘潭的比赛中的一个求平方和的题目思路很类似. 首先说一下hash,简单来说就是y = hash(x),有很多函数,可以参考这里:https://www.byvoid.com/blog/string-hash-compare/ 然后,我用的是这个:写法简单,而且重复的可能较小. // BKDR Hash Fu

(并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )

http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2061    Accepted Submission(s): 711 Problem Description Jack likes to travel around the wo

2015 ACM/ICPC Asia Regional Changchun Online HDU 5444 Elven Postman【二叉排序树的建树和遍历查找】

Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 591    Accepted Submission(s): 329 Problem Description Elves are very peculiar creatures. As we all know, they can live for a very

2015ACM/ICPC Asia Regional Changchun Online /HDU 5438 图

Ponds                                   Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)                                        Problem Description Betty owns a lot of ponds, some of them are connected with other

hdu 5444 Elven Postman(根据先序遍历和中序遍历求后序遍历)2015 ACM/ICPC Asia Regional Changchun Online

很坑的一道题,读了半天才读懂题,手忙脚乱的写完(套上模板+修改模板),然后RE到死…… 题意: 题面上告诉了我们这是一棵二叉树,然后告诉了我们它的先序遍历,然后,没了……没了! 反复读题,终于在偶然间注意到了这一句——"Not only that, when numbering the rooms, they always number the room number from the east-most position to the west." 它告诉我们,东边的点总是比西边的点

Hdu 5442 Favorite Donut (2015 ACM/ICPC Asia Regional Changchun Online 最大最小表示法 + KMP)

题目链接: Hdu 5442 Favorite Donut 题目描述: 给出一个文本串,找出顺时针或者逆时针循环旋转后,字典序最大的那个字符串,字典序最大的字符串如果有多个,就输出下标最小的那个,如果顺时针和逆时针的起始下标相同,则输出顺时针. 解题思路: 看到题目感觉后缀数组可以搞,正准备犯傻被队友拦下了,听队友解释一番,果断丢锅给队友.赛后试了一下后缀数组果然麻烦的不要不要的(QWQ),还是最大最小表示法 + KMP来的干净利索. 最大表示法:对于一个长度为len文本串,经过循环旋转得到长度