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组成.在共同的集训生活中,大家建立了深厚的 ...
随机推荐
- _BLOCK_TYPE_IS_VALID错误
_BLOCK_TYPE_IS_VALID宏用来检测这个内存块在当前堆上是否有效,但是这里的指针是一个临时变量,临时变量是在栈上分配的,函数清理栈时会自动回收这些内存,程序员无需管理. new 和 ma ...
- A Typical Homework(学生信息管理系统)
A Typical Homework(a.k.a Shi Xiong Bang Bang Mang) Hi, I am an undergraduate student in institute of ...
- CDZSC_2015寒假新人(2)——数学 D
D - D Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- 3D Touch:静态快速启动方式
原文传送门:Add iOS 9’s Quick Actions shortcut support in 15 minutes right now ! 苹果在iOS9 上引入3D触控(压力触控)功能 ...
- Uubntu scrot 的简单使用
scrot 是一个使用 imlib2 库截取屏幕和保存图像的的工具. 1:安装 #apt-get install scrot 2:查看帮助 #scrot -help -v, --version显示版本 ...
- 查看oracle中的中文所占字节数
select userenv('language') from dual 显示:SIMPLIFIED CHINESE_CHINA.ZHS16GBK 表示一个汉字占用两个字节. 显示:SIMPLIFIE ...
- C# unsafe code
(*) unsafe 和 fixed unsafe { ]; ; i < array.Length; i++) { arra ...
- Median of Two Sorted Arrays 解答
Question There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median o ...
- 搜索和搜索形式(SEARCHING and its forms)
什么是搜索? 在计算机科学中,搜索就是在一个事物的集合中找到具有特定特征的一项的过程.这些集合中的元素可能是排好序的数据库中的记录,简单数组中的数据,文件中的文本,树中的节点,几何图形中的点和边或者是 ...
- python hook监听事件
python hook监听事件 作者:vpoet mail:vpoet_sir@163.com # -*- coding: utf-8 -*- # # by oldj http://oldj.net/ ...