zoukankan      html  css  js  c++  java
  • 2011ACM福州网络赛第一题 A Card Game(水题)

    A Card Game

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 4    Accepted Submission(s): 3


    Problem Description
    There are N cards on the table, whose front side is writen one integer number from 1 to M. We call one card "a type k card" if its number is k. The quantity of type i cards is a_i.
    Let's play a game with these cards. We divide these cards into M piles by random with the only constrains that the quantity of cards in i-th (indexed from 1) pile must exactly be a_i. The possbility of each card appears in i-th pile is directly proportional to the size of this pile. That is to say, if the size of a pile is A, the possibility for each card appears in this pile is A/N assuming that N is the amount of all cards. We choose pile 1 to start the game. Assuming the we now play this game at pile k, we randomly choose a card from pile k with the same possibility for all cards in it, remember the number written on this card and throw it away. If the number on the chosen card is j, we continue this game at pile j on next round. The game terminates when we are going to get a card from an empty pile.

    Now the question is, when the game ends, what is the possibility that all piles are empty?
     

    Input
    There is only one input file. The first line is the number of test cases T. T cases follow, each of which contains two lines. The first line is an integer M (1 <= M <= 100), the number of type of cards (and the number of piles, they are exactly the same). The second line contains M positive integers not greater than 1000, the i-th number of which is a_i.
     

    Output
    For each test case, output the possibility you are required to calculate. Answers are rounded to 6 numbers after the decimal point.(as shown in the sample output)
     

    Sample Input
    2 1 5 2 1 2
     

    Sample Output
    Case 1: 1.000000 Case 2: 0.333333
     
    水题,看代码:
    这样的题目很爽!
     
    #include<stdio.h>
    int main()
    {
        int T;
        int iCase=0;
        int a;
        int n;
        int ans,res;
        scanf("%d",&T);
        while(T--)
        {
            iCase++;
            scanf("%d",&n);
            scanf("%d",&ans);
            res=ans;
            for(int i=1;i<n;i++)
            {
                scanf("%d",&a);
                res+=a;
            }    
            printf("Case %d: %.6lf\n",iCase,(double)ans/res);
        }    
        return 0;
        
    }    
    

  • 相关阅读:
    美国队长清晰TC中字 迅雷下载+ 美国队长 漫画 复仇者迅雷下载
    【转】腾讯、人人、新浪社交网络优劣势分析(转自月光博客)
    【技术贴】NVIDIA控制面板设,显示屏输入信号超出范围
    【技术贴】怎么拖动vs2008的控件
    SQL Server 2000/2005检测存储过程名是否存在,存在删除
    asp.net生成HTML
    gridview列 数字、货币和日期 显示格式
    用C#编写托盘程序
    判断地址栏参数,为空或null
    C# 读取计算机CPU,HDD信息
  • 原文地址:https://www.cnblogs.com/kuangbin/p/2200549.html
Copyright © 2011-2022 走看看