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
“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!?
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]?
3 0.5
1 2 3
一开始想法是对的,但是实现起来没弄好。
用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的更多相关文章
- HDU 4822 Tri-war(LCA树上倍增)(2013 Asia Regional Changchun)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4822 Problem Description Three countries, Red, Yellow ...
- HDU 4816 Bathysphere(数学)(2013 Asia Regional Changchun)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spheric ...
- 2013 Asia Regional Changchun I 题,HDU(4821),Hash
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4821 解题报告:搞了很久,总算搞出来了,还是参考了一下网上的解法,的确很巧,和上次湘潭的比 ...
- 2013 Asia Regional Changchun
Hard Code http://acm.hdu.edu.cn/showproblem.php?pid=4813 #include<cstdio> ]; int main(){ int t ...
- 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 ...
- (并查集)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 ...
- (二叉树)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) ...
- 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 ...
- 2015ACM/ICPC Asia Regional Changchun Online /HDU 5438 图
Ponds Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 1310 ...
随机推荐
- H5页面微信分享和手Q分享设置
RT: 一. 手Q分享: 如下代码所示:设置好 description,name,image,即可,唯一注意的是image最好是200*200,要不然过小不美观,过大加载太慢 <head> ...
- JAVA中使用FTPClient实现文件上传下载实例代码
一.上传文件 原理就不介绍了,大家直接看代码吧 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...
- Integrating SharePoint 2013 with ADFS and Shibboleth
Time again to attempt to implement that exciting technology, Federation Services (Web Single Sign On ...
- [LeetCode] Word Squares 单词平方
Given a set of words (without duplicates), find all word squares you can build from them. A sequence ...
- [LeetCode] Random Pick Index 随机拾取序列
Given an array of integers with possible duplicates, randomly output the index of a given target num ...
- 基本组件的使用——UINavigationController
作用:在多个ViewController中切换.UINavigationController内部以栈的形式维护一组ViewController, 因此,当导航进入一个新视图的时候,会以push的形式将 ...
- Redis 常用操作
import org.junit.Before;import org.junit.Test;import redis.clients.jedis.Jedis;import java.util.Set; ...
- python基础补漏-06-其他常用模块
JSON/Pickle: 首先我们要明白 什么事序列化--> 就是进行不同程序之间的数据交换 那JSON 和Pickle是什么鬼... 就是不同的方式而已 import json name = ...
- 在页面的el表达式是如何判断null的
<c:if test="${not empty message}"> <div id="message" class="alert ...
- 分享一些平时测试用的sql payloads
1:BOOL SQLINJECTION \'"%df'%df" and 1=1 and 1=2' and '1'='1' and '1'='2" and "1& ...