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组成.在共同的集训生活中,大家建立了深厚的 ...
随机推荐
- (转+原)ipp "No dlls were found in the Waterfall procedure"
转自: http://blog.csdn.net/hua_007/article/details/9112909 1,吧 dll的目录放到系统环境变量中 intel 的官方推荐.验证是ok的. --- ...
- OS X EI Capitan 10.11.4中sudo无法起作用的解决方法
mac升级到OSX EI Capitan 10.11.4后sudo命令无法起作用,执行任何操作总是显示Operation denied.这是因为在10.11.4中引入了Rootless机制,即就算是R ...
- new String(byte[])和byte[]toString() 的区别
byte[]字节数组的toString()获得的字符串和使用new String(byte[])构造一个新的字符串,这两个字符串是不一样的.Java对象都继承于Object,Object中提供了toS ...
- 网易2014校园招聘杭州Java笔试题
10) ABC http://soft.chinabyte.com/os/56/12516056.shtml 11) BD. 12) AC. http://blog.sina.com.cn/s/blo ...
- Android IntentService 与Alarm开启任务关闭任务
1:MyService public class MyService extends IntentService{ AlarmManager alarmManager = null; PendingI ...
- jQuery插件之validate
一.jQuery.validate.js插件用于对表单输入进行验证,其使用配置非常简单.支持多事件触发,自带多种验证规则,还支持自定义验证规则. 1.配置方法. 先导入jQuery库,然后导入Vali ...
- UESTC_秋实大哥搞算数 2015 UESTC Training for Data Structures<Problem N>
N - 秋实大哥搞算数 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Subm ...
- Implement Queue using Stacks 解答
Question Implement the following operations of a queue using stacks. push(x) -- Push element x to th ...
- LeeCode-Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- python-pcap模块解析mac地址
python-pcap模块解析mac地址 作者:vpoet mail:vpoet_sir@163.com import pcap import binascii a = pcap.pcap() a.s ...