AGU13-Save The Princess

2 篇文章 0 订阅

题目来源: http://www.codechef.com/AUG13/problems/SHIRO

题目描述:

Shiro is leading an army to save the princess of his kingdom "Abra". The princess has been made a prisoner by the neighboring kingdom "Kadabra". Kadabra is a magical land and is full of challenges. Shiro's army has to passN levels before they can get to the princess. After each level, the army gets a few flags to carry along. The flags can either all be of kindom Abra OR all of kingdom Kadabra. The magic of Kadabra forces Shiro's army to carry the flags irrespective of which kingdom they belong to. The princess doesn't know Shiro or anyone from his army. She will not escape with them unless she can trust them. She will trust them only if the number of Abra's flags they are carrying is atleast as much as the number of Kadabra's flags.

The army gets ai flags at the end of the ith level. Probability that flags received at the end of the ith level will be Abra's flags ispi. Your task is to tell Shiro what is the probability that the princess will trust him once they reach her.

Input:

First line of input contains a single integer T, the number of test cases.

Each test starts with a single line having an integer, N, the number of levels in Kadabra.

Next line contains contains N integers with the ith integer beingai as described above.

Next line contains contains N integers with the ith integer beingpi as described above. Note that the probabilities given will be in percents.

Output:

For each test case, output a line containing the required probability. The answer will be accepted if the relative error is not more than 10-6.

Constraints:

1 ≤ T ≤ 100
1 ≤ N ≤ 100
1 ≤ ai ≤ 100
0 ≤ pi ≤ 100

Example:

Input:

2
5
1 2 3 4 4
0 100 100 0 50
2
5 5
50 60

Output:

0.5000000
0.8000000


题目大概意思:求Abra旗帜的个数大于等于总旗帜一半的概率,如第二组数据,一共有0,5,10,三种可能性,则p=0.5*0.6+0.5*0.4+0.5*0.6=0.8;

所以可以有一个递归式 Pro[j]=Pro[j]*(1-p[i])+Pro[j-a[i]]*p[i]   也就是DP。

最后求Pro[sum/2]~Pro[sum]的和


代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#define MAX 10010
using namespace std;
double Pro[MAX];
int a[110];
double p[110];
int N;
int sum=0;
void input()
{
   scanf("%d",&N);
   for(int i=1;i<=N;i++)
   {
       scanf("%d",&a[i]);
       sum+=a[i];
   }
   for(int i=1;i<=N;i++)
   {
       int c;
       scanf("%d",&c);
       p[i]=(double)c/100;
   }
}
void solve()
{
   for(int i=1;i<=N;i++)
   {
       for(int j=MAX;j>=a[i];j--)
       {
           Pro[j]=Pro[j]*(1-p[i])+Pro[j-a[i]]*p[i];
       }
       for(int k=0;k<a[i];k++)
         Pro[k]=Pro[k]*(1-p[i]);
   }
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        memset(Pro,0,sizeof(Pro));
        Pro[0]=1;
        input();
        solve();
        double ans=0;
        for(int i=((sum+1)/2);i<=sum;i++)
          {
              //printf("%.5f\n",Pro[i]);
              ans+=Pro[i];
          }
        printf("%.7f\n",ans);
        sum=0;
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
AgU2701A_reset是一个重置命令,用于重置AgU2701A设备。根据引用中提到的方法2,可以使用以下命令来重置RabbitMQ:rabbitmqctl stop_app,rabbitmqctl reset,rabbitmqctl start_app。这些命令将停止RabbitMQ应用程序,重置RabbitMQ的状态,然后重新启动应用程序。这样可以清除任何可能导致问题的配置或数据,并将RabbitMQ恢复到初始状态。但需要注意的是,在执行重置命令之前,请确保备份了重要的配置和数据,以免丢失重要信息。如果执行重置后仍然遇到问题,可能需要查看引用中提到的错误信息,并根据具体错误信息进行进一步调查和解决。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [RabbitMQ--安装/配置/使用](https://blog.csdn.net/feiying0canglang/article/details/106932556)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [基于Verilog的FFT模块实现](https://blog.csdn.net/ccsss22/article/details/122889849)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值