U - 神、上帝以及老天爷(第二季水)
Description
首先,所有参加晚会的人员都将一张写有自己名字的字条放入抽奖箱中; 然后,待所有字条加入完毕,每人从箱中取一个字条; 最后,如果取得的字条上写的就是自己的名字,那么“恭喜你,中奖了!”
大家可以想象一下当时的气氛之热烈,毕竟中奖者的奖品是大家梦寐以求的Twins签名照呀!不过,正如所有试图设计的喜剧往往以悲剧结尾,这次抽奖活动最后竟然没有一个人中奖!
我的神、上帝以及老天爷呀,怎么会这样呢?
不过,先不要激动,现在问题来了,你能计算一下发生这种情况的概率吗?
不会算?难道你也想以悲剧结尾?!
Input
Output
Sample Input
Sample Output
#include<iostream>
#include<iomanip>
using namespace std;
long double s1[25],s2[25],x,y;
void f(int n)
{
s1[0]=1;
s1[1]=1;
s1[2]=1;
s1[3]=2;
for(int i=4;i<21;i++){
s1[i]=(i-1)*(s1[i-2]+s1[i-1]);
}
s2[n]=1;
for(int i=1;i<=n;i++)s2[n]*=i;
long double x;
cout<<setiosflags(ios::fixed)<<setprecision(2);
cout<<100*s1[n]/s2[n]<<"%"<<endl;
}
int main()
{
int n;
cin>>n;
while(n--){
int a;
cin>>a;
if(a==1)cout<<"0.00%"<<endl;
else f(a);
}
//system("pause");
return 0;
}
U - 神、上帝以及老天爷(第二季水)的更多相关文章
- F - The Fun Number System(第二季水)
Description In a k bit 2's complement number, where the bits are indexed from 0 to k-1, the weight o ...
- D - Counterfeit Dollar(第二季水)
Description Sally Jones has a dozen Voyageur silver dollars. However, only eleven of the coins are t ...
- S - 骨牌铺方格(第二季水)
Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数. 例如n=3时,为2× 3方格,骨牌的铺放方案有三种, ...
- R - 一只小蜜蜂...(第二季水)
Description 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数. 其中,蜂房的结构如下所示. ...
- I - Long Distance Racing(第二季水)
Description Bessie is training for her next race by running on a path that includes hills so that sh ...
- Y - Design T-Shirt(第二季水)
Description Soon after he decided to design a T-shirt for our Algorithm Board on Free-City BBS, XKA ...
- N - Robot Motion(第二季水)
Description A robot has been programmed to follow the instructions in its path. Instructions for the ...
- B - Maya Calendar(第二季水)
Description During his last sabbatical, professor M. A. Ya made a surprising discovery about the old ...
- T - 阿牛的EOF牛肉串(第二季水)
Description 今年的ACM暑期集训队一共有18人,分为6支队伍.其中有一个叫做EOF的队伍,由04级的阿牛.XC以及05级的COY组成.在共同的集训生活中,大家建立了深厚的 ...
随机推荐
- 类似QQ侧滑菜单功能实现
之前的那文章简单实现了菜单侧拉功能,但是做不到像QQ那样导航条和tabBar一起移动...之后在网上找资料,有了思路,就自个写了个demo试试水. 先创建QHLMainController控制器,并把 ...
- (转) mac 下的eclipse 配置 python 2.7
原地址: http://marsfreewill.blogspot.it/2012/08/mac-ospythonpydeveclipse.html 在MAC OS上配置Python开发环境(Py ...
- (原)lua提示cannot load incompatible bytecode
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5754872.html 前段时间用终端和zerobrane运行torch的lua程序.zerobrane ...
- linux下python多版本共存
为何要安装python,linux下不是已经集成了python吗? 大多数linux系统都集成了python,但是他们的版本太低了.不能满足我们的需求,尤其是好多系统居然仍停留在 python2.6. ...
- sqlCacheDependency 更新缓存Cache
第一步 修改web,config <!--定义数据库连接--> <connectionStrings> <add name="NorthwindConnect ...
- [转]fatal error: iostream.h: No such file or directory
iostream.h是非标准头文件,iostream是标准头文件形式.iostream.h时代没有名词空间,即所有库函数包括头文件iostream.h都声明在全局域.为了体现结构层次,c++标准委员会 ...
- 负载均衡集群之LVS的DR模型详解(Diretor Routing)
LVS的默认模型:默认模型DR DR模型原理图--> 在讲DR模型要点之前,需要了解网络的相关知识: 接收的报文拆解顺序:帧(MAC)-->数据包(IP)-->数据报文(port) ...
- 关于url拼接传参数和利用view的字典传参数时,模板获取数据的方式问题
url = "{% url 'dashboard:internship-theme-stat' %}?teacher_name="+teacher_name+"& ...
- codeforce343A
题目地址:http://codeforces.com/problemset/problem/343/A 比赛的时候就囧了,只推出a<b的时候最少需要b个电阻. 后来看了题解,知道 题意:用最少的 ...
- codecomb 2085【肥得更高】
题目背景 自2009年以来,A.B站的历史就已经步入了农业变革的黎明期. 在两站的娱乐及音乐区,金坷垃制造业早已得到长足的发展,甚至有些地方还出现了坷垃翻唱的萌芽. 新兴肥料人开始走上历史的舞台. 他 ...