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. Android ListView ArrayAdapter 的简单使用

    前面写了3篇关于android的文章,其中的演示程序都写在了一个工程中,当时为了方便测试就在启动页MainActivity中放了3个按钮,点击不同的按钮进入不同的示例程序页面,MainActivity ...

  2. 使用jekins自动构建部署java maven项目(jdk1.7+tomcat7.0+jenkins2.19.3)

    1.下载jenkins 地址:https://jenkins.io/index.html 本人下载了2.19.3版本的war包:jenkins.war 2.安装jenkins 拷贝jenkins.wa ...

  3. get方式和set方式提交时乱码

    request.setChracterEncoding("utf-8");只对form表单的post提交方式有效. 当使用get提交的时候:

  4. spring3系列一

    IOC基础 Ioc是什么 Ioc--Inversion of Control 控制反转,不是什么技术,而是一种设计思想.在java开发中,ioc意味着将你设计好的对象交给容器控制,而不是传统的在你的对 ...

  5. word-break|overflow-wrap|word-wrap——CSS英文断句浅析

    ---恢复内容开始--- word-break|overflow-wrap|word-wrap--CSS英文断句浅析 一 问题引入 今天在再次学习 overflow 属性的时候,查看效果时,看到如下结 ...

  6. [LeetCode] Interleaving String 交织相错的字符串

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 ...

  7. 5G系统架构

    原文标题:迈向5G之路,颠覆性的5G系统架构?   本文部分图片,资料摘自<迈向5G C-RAN:需求.架构与挑战> 突如一夜春风来,随着Polar码与LDPC码作为5G编码候选方案,通信 ...

  8. Java并发_volatile实现可见性但不保证原子性

    读后感 介绍了volatile实现可见性的基本原理 介绍了volatile不能实现原子性的示例,volatile复合操作不能实现原子性,读取值后在自增前改值可能被其它线程读取并修改,自增后刷新值可能会 ...

  9. 进度条投票-W

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  10. localForage——轻松实现 Web 离线存储(转)

    localStorage 能够让你实现基本的数据存储,但它的速度慢,而且不能处理二进制数据.IndexedDB 和 WebSQL 是异步的,速度快,支持大数据集,但他们的API 使用起来有点复杂.不仅 ...