WHU 2013 Summer random contest #2 F题

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27749#problem/F

直接使用组合进行计算,在打表的时候使用组合公式从下到上进行打表。

注意不要使用long long 型的数乘以 double型的数而是直接用double 充当结果一路往下乘积,否则会wa。

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
#define MAXN 55
using namespace std;
typedef long long LL;
double prb[MAXN];
int num[MAXN];
int ct[MAXN];
double ans;
LL f[MAXN+100][MAXN+100];
void zuhe()
{
    for(int i=0;i<55;i++)
    {
        for(int j=0;j<55;j++)
             f[i][j]=1;
    }
    for(int i=1;i<51;i++)
    {
        for(int j=1;j<=i;j++)
        {
            if(i>0&&j>0&&i>j)
               f[i][j]=f[i-1][j-1]+f[i-1][j];
        }
    }
//    for(int i=0;i<55;i++)
//    {
//        for(int j=0;j<i;j++)
//        {
//            cout<<"f: "<<i<<' '<<j<<": "<<f[i][j]<<endl;
//        }
//    }
}
void init()
{
    int m;
    cin>>m;
    for(int i=1;i<=m;i++)
       cin>>prb[i];

}
int main()
{
    zuhe();
    int cas;
    cin>>cas;
    int casct=0;
    while(cas--)
    {
        casct++;
        printf("Test Case #%d:\n",casct);
        init();
        int cas2;
        cin>>cas2;
        while(cas2--)
        {
            int n;
            cin>>n;
            ans=1;
            memset(ct,0,sizeof(ct));
            for(int i=0;i<n;i++)
            {
                cin>>num[i];
                ans*=prb[num[i]];
                ct[num[i]]++;
            }
            int sum=0;
            for(int i=0;i<55;i++)
            {
               // cout<<"sum: "<<sum<<endl;
               // cout<<"ct: "<<i<<' '<<ct[i]<<endl;
               // getchar();
               ans*=f[n-sum][ct[i]];
              //  cout<<"f: "<<f[n-sum][ct[i]]<<endl;
                sum+=ct[i];
            }
            //cout<<"comp: "<<comp<<endl;
            int exp=0;
            while(ans<1)
            {
                    ans*=10;
                    exp++;
            }
                printf("%.5f x 10^%d\n",ans,-1*exp);
        }
    }
}


 

F - F

Crawling in process... Crawling failed Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

 

Description

Download as PDF

Do you know Lotto? Lotto is a game of probability. Six numbers are drawn from a range of numbers (such as 42, 47, 47, 49, 51, and 54). Michigan, for instance, has a 6-out-of-47 game (6/47), meaning that six numbers are drawn from possible 47. Florida's Lotto is 6/53, meaning that six numbers are drawn from a possible 53.

To play Lotto, indicate your six chosen numbers by marking the numbered squares on a play slip. Then take the play slip to a lottery retailer (or agent). The retailer enters your selection in the on-line terminal, which produces your game ticket. The ticket, not the play slip, is the official receipt and must be presented and validated in the event of a win. Always check to make sure that the correct date and numbers are on the game ticket before you leave. Lottery agents are found in convenience stores, gas stations, and grocery stores.

The cost for one chance at Lotto is still $1 in many states. So for one chance, or play, at Lotto, you would pay $1. For five plays -- that is, to play five sets of numbers--you would pay $5. Illinois offers a bargain: two plays for $1.

Typically, Lotto drawings are held twice a week, usually on Wednesday and Saturday nights. However, this may not be true for every state.

The lottery officials use special ball-drawing machines, and the balls are numbered. The machine randomly shoots out six selected balls; these balls display the winning numbers for that evening's lottery drawing. If all six of your numbers exactly match the numbers drawn, you win the jackpot. In Lotto, your numbers don't need to be listed in any particular order, as long as they match those drawn. (taken from http://entertainment.howstuffworks.com/how-to-play-the-lottery1.htm)

In most case of lottery they don't draw same number, but in our problem here same number are allowed. So here, you can play number "42 42 45 45 45" which is not allowed in common lottos.

They say there's more chance of you getting hit by a car on your way to buy a lotto ticket than the chance of winning one. Is the probability to win really that small? You are about to help me find out.

Input

Input starts with an integer T (1 <= T <= 10), the number of test cases. T input blocks follows. Each input blocks starts with an integer M (1 <= M <= 50), meaning that the game involves M distinct numbers particularly from 1 to M. You don't know how the ball-drawing machine works, but you do know that for there is a constant probability for each number to pop up. The second line of each input blocks will consists of M real-numbers P1, P2, P3, P4, ..., PM, where Pi denotes the probability of ball with number i to pop-up. You can safely assume that the total probability is equal to 1.

The third line of input is an integer Q (1 <= Q <= 100), the number of queries. Q lines follow with each line begins with an integer N (1 <= N <= M). So if N is 6, you are playing 6-out-of-M game in this particular query. N numbers follows, those are your chosen number. You are to determine what is the probability of that number winning the lottery. Since the probabilities can be very low, output them in scientific notation: a x 10^b where a should be between 1.00000 and 9.99999, inclusive. Output a in 5 decimal places.

Output

For each query, you are to determine the probability of that number winning the lottery.

Sample Input

2
5
0.2 0.2 0.2 0.2 0.2
3
3 1 2 3
4 5 5 5 5
1 3
3
0.2 0.3 0.5
2
1 1
2 2 1

Sample Output

Test Case #1:
4.80000 x 10^-2
1.60000 x 10^-3
2.00000 x 10^-1
Test Case #2:
2.00000 x 10^-1
1.20000 x 10^-1

 

你可能感兴趣的:(Random)