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

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

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

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
#include<vector>
#define M(a,b) memset(a,b,sizeof(a))
#define eps 1e-6
using namespace std; double p;
int n;
int num[];
double dp[][];
int cnt; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%lf",&n,&p);
//long long a = pow(2,(long long)n);
for(int i = ;i<n;i++)
{
scanf("%d",&num[i]);
}
M(dp,);
dp[][] = ;
for(int i = ;i<n;i++)
{
for(int j = ;j<*n;j++)
{dp[i+][j] += dp[i][j]*0.5;
dp[i+][j+num[i]]+= dp[i][j]*0.5;}
}
double res = ;
int ans = ;
for(int i = *n;i>=;i--)
{
res+=dp[n][i];
if(res>-p) {ans = i; break;}
}
printf("%d\n",ans);
}
return ;
}
/*
1
3 0.1
1 2 3
10
40 0.5
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
10
10 0.7
1 2 3 2 3 2 1 1 3 4
13 */

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

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
#include<vector>
#define M(a,b) memset(a,b,sizeof(a))
#define eps 1e-6
using namespace std; double p;
int n;
int num[];
int cnt;
double m[];
double pls[];
int which[];
long long a; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%lf",&n,&p);
a = pow(,n);
for(int i = ;i<n;i++)
{
scanf("%d",&num[i]);
}
M(m,);
m[] = 1.0/a;
for(int i = ;i<n;i++)
{
int cnt = ;
for(int j = ;j<;j++)
{
if(m[j]>)
{
pls[cnt] = m[j];
which[cnt] = j+num[i];
cnt++;
}
}
for(int i = ;i<cnt;i++)
{
m[which[i]] += pls[i];
}
}
double res = ;
int ans = ;
for(int i = ;i<;i++)
{
res+=m[i];
if(res>=p) {ans = i; break;}
}
//cout<<a<<endl;
//cout<<ct<<endl;
printf("%d\n",ans);
}
return ;
}
/*
1
3 0.1
1 2 3
10
40 0.5
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
10
10 0.7
1 2 3 2 3 2 1 1 3 4
13 */

2013 Asia Regional Changchun C的更多相关文章

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4822 Problem Description Three countries, Red, Yellow ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spheric ...

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

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4821 解题报告:搞了很久,总算搞出来了,还是参考了一下网上的解法,的确很巧,和上次湘潭的比 ...

  4. 2013 Asia Regional Changchun

    Hard Code http://acm.hdu.edu.cn/showproblem.php?pid=4813 #include<cstdio> ]; int main(){ int t ...

  5. hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online

    Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...

  6. (并查集)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)    Memo ...

  7. (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)

    http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others)  ...

  8. 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)T ...

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

    Ponds                                   Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 1310 ...

随机推荐

  1. Compiler Error Message: CS0016: Could not write to output file 回绝访问

    Compiler Error Message: CS0016: Could not write to output file 'c:\Windows...dll' 拒绝访问 C:\Windows\Te ...

  2. Class.forName和ClassLoader.loadClass等

    Class类 首先,Class类里可以记载所有类的属性.方法等信息.这个也就是运行时类别标记,它记录了所有的对象(比如int,MyClass,void,数组等等)对应的类信息. Class对象 JVM ...

  3. [LeetCode] Perfect Rectangle 完美矩形

    Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover o ...

  4. [LeetCode] H-Index 求H指数

    Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...

  5. C#进阶系列——WebApi 接口参数不再困惑:传参详解

    前言:还记得刚使用WebApi那会儿,被它的传参机制折腾了好久,查阅了半天资料.如今,使用WebApi也有段时间了,今天就记录下API接口传参的一些方式方法,算是一个笔记,也希望能帮初学者少走弯路.本 ...

  6. ElasticSearch+Kibana 索引操作( 附源码)

    一 前言 ElasticiSearch 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elastics ...

  7. VehicleCamera解读

    坐标系: z-axis ^ | | y-axis | / | / |/ +----------------> x-axis 围绕Z轴旋转叫做偏航角,Yaw:围绕X轴旋转叫做 俯仰角,Pitch: ...

  8. 创建ejs模板的express工程

    npm install -g express npm install -g express-generator express -e projectName cd projectName npm in ...

  9. 客户端Socket

    导语 java.net.Socket类是JAVA完成客户端TCP操作的基础类.其他建立TCP网络连接的类(如URL,URLConnection和EditorPane)最终会调用这个类的方法.这个类本身 ...

  10. C# Winform代码片段-大二下学期的垃圾代码

    1.图片缩放 using System; using System.Windows.Forms; using System.Drawing; class haha : Form { static vo ...