第六周 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 ...
随机推荐
- 【python,logging】python中的logging模块
本文章转自kenby的博客,比较全面易懂,转来留作以后使用. http://kenby.iteye.com/blog/1162698 一.从一个使用场景开始 import logging # 创建一个 ...
- iOS 多线程讲解
//同步操作用途 dispatch_queue_t queue = dispatch_get_global_queue(0, 0); dispatch_sync(queue, ^{ NSLog(@&q ...
- android studio1.3安装终于成功
本人机器是win7 32位旗舰版,4G内存.以前使用eclipse adt bundle开发Android程序感觉非常方便,但随着google对andriod studio支持力度加大,转向studi ...
- PHP中正则替换函数preg_replace用法笔记
今天应老板的需求,需要将不是我们的页面修改一个链接,用js+iframe应该也能实现,但是我想尝试一下php实现方法. 首先你得先把别人的页面download到你的php中,实现方法可以用curl, ...
- codeforces 678C C. Joty and Chocolate(水题)
题目链接: C. Joty and Chocolate time limit per test 1 second memory limit per test 256 megabytes input s ...
- 配置JDK和TOMCAT
配置JDK 1.先从官网下载最新的JDK安装包,然后安装.安装过程中会询问是否再装JRE,因为JDK中已经包含JRE,所以不必重复安装. 2.注意安装的路径名最好不要有中文或者空格出现. 3.在系统环 ...
- Server.MapPath()获取绝对路径
1. Server.MapPath("/") 应用程序根目录所在的位置 如 C:\Inetpub\wwwroot\ 2.Server.MapPath("./&qu ...
- ASP.NET 窗体间传值实现方法详解
假设ParentForm.aspx 页面上有TextBox1文本框和Open按钮点击Open按钮弹出SubForm.aspx,SubForm.aspx页面上有TextBox1文本框和Close按钮点击 ...
- vlan知识
为什么需要VLAN 1. 什么是VLAN? VLAN(Virtual LAN),翻译成中文是“虚拟局域网”.LAN可以是由少数几台家用计算机构成的网络,也可以是数以百计的计算机构成的企业网络.VLAN ...
- JavaScript 弹窗
JavaScript 弹窗 可以在 JavaScript 中创建三种消息框:警告框.确认框.提示框. 警告框 警告框经常用于确保用户可以得到某些信息. 当警告框出现后,用户需要点击确定按钮才能继续进行 ...