第六周 N题
Description
As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (he wants everything quick!) so he decided to rob banks. He wants to make a calculated risk, and grab as much money as possible. But his friends - Hermione and Ron have decided upon a tolerable probabilityP of getting caught. They feel that he is safe enough if the banks he robs together give a probability less than P.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains a real number P, the probability Harry needs to be below, and an integer N (0 < N ≤ 100), the number of banks he has plans for. Then follow N lines, where line j gives an integer Mj (0 < Mj ≤ 100) and a real number Pj . Bank j contains Mj millions, and the probability of getting caught from robbing it is Pj. A bank goes bankrupt if it is robbed, and you may assume that all probabilities are independent as the police have very low funds.
Output
For each case, print the case number and the maximum number of millions he can expect to get while the probability of getting caught is less than P.
Sample Input
3
0.04 3
1 0.02
2 0.03
3 0.05
0.06 3
2 0.03
2 0.03
3 0.05
0.10 3
1 0.03
2 0.02
3 0.05
Sample Output
Case 1: 2
Case 2: 4
Case 3: 6
#include <stdio.h>
#include <string.h>
int N[];
double P[],d[];
double max(double a,double b)
{
return a>b?a:b;
}
int main()
{
int T,c=;
scanf("%d%",&T);
while(T--)
{
c++;
int n,total=;
double p;
memset(d,,sizeof(d));
d[]=;
scanf("%lf%d",&p,&n);
for(int i=; i<n; i++)
{
scanf("%d%lf",&N[i],&P[i]);
total+=N[i];
} for(int i=;i<n;i++)
{
for(int j=total;j>=N[i];j--)
{
d[j]=max(d[j],d[j-N[i]]*(-P[i]));
//printf("%d %lf\n",j,d[j]);
}
}
for(int i=total;i>=;i--)
{
// printf("%lf %d\n",d[i],i);
if(d[i]>=-p)
{
printf("Case %d: %d\n",c,i);
break;
}
}
}
return ;
}
第六周 N题的更多相关文章
- 程序设计入门—Java语言 第六周编程题 1 单词长度(4分)
第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这 ...
- hdu 4548 第六周H题(美素数)
第六周H题 - 数论,晒素数 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- Codeforces 559A 第六周 O题
Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...
- 第六周 E题 期望.....
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
- HDU 1465 第六周L题
Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. ...
- HDU 1405 第六周 J题
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all ...
- HDU 2669 第六周 I题
Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the ...
- 第六周O题(等边三角形个数)
O - 计数 Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Descripti ...
- HDU1465 第六周L题(错排组合数)
L - 计数,排列 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descrip ...
随机推荐
- Gradle实战:不同编译类型的包同设备共存
查看原文:http://blog.csdn.net/u010818425/article/details/52335844 Gradle实战系列文章: <Gradle基本知识点与常用配置> ...
- 获取JDK动态代理/CGLIB代理对象代理的目标对象。
问题描述:: 我现在遇到个棘手的问题,要通过spring托管的service类保存对象,这个类是通过反射拿到的,经过实验发现这个类只能反射取得sservice实现了接口的方法,而extends类的方法 ...
- uboot在s3c2440上的移植(2)
一.移植环境 主 机:VMWare--Fedora 9 开发板:Mini2440--64MB Nand,Kernel:2.6.30.4 编译器:arm-linux-gcc-4.3.2.tgz u-b ...
- Flips测试类(page43)
测试用例:所用java类: StdOut,StdIn , Counter, StdRandom, public class Flips { public static void main(String ...
- python之supervisord启动脚本
Supervisord是用Python实现的一款非常实用的进程管理工具,在批量服务化管理时特别有效.可以将非Daemon的应用转为daemon程序.关于supervisord的安装和配置,在网上已经有 ...
- GSS4 2713. Can you answer these queries IV 线段树
GSS7 Can you answer these queries IV 题目:给出一个数列,原数列和值不超过1e18,有两种操作: 0 x y:修改区间[x,y]所有数开方后向下调整至最近的整数 1 ...
- 用jquery 实现 超出字符 截断加上省略号并且可以提示全部内容
1.test.jsp Java代码 <%@ page language="java" pageEncoding="UTF-8"%> <html ...
- 【CSS3】---嵌入字体@font-face
@font-face能够加载服务器端的字体文件,让浏览器端可以显示用户电脑里没有安装的字体. 语法: @font-face { font-family : 字体名称; src : 字体文件在服务器上的 ...
- 用Drawing画图如何不会消失
方法一:将事件放在form_Load中,在窗体中画图 1: protected void MainForm_Load(object sender,EventArgs e) 2: { 3: Init ...
- slickgrid 一个优秀的JS表格插件
从熟悉JS以来,慢慢的喜欢上了这个门语言. 不自觉的,看了好多js的知识,可能也是因为做项目的原因吧. 这里稍微说下一个JS的grid插件 --slickgrid 了解这个插件也不是很多,稍微了解了下 ...