poj 6243 Dogs and Cages
Dogs and Cages
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 56 Accepted Submission(s): 40
Special Judge
dogs numbered 0,1,...,N−1
. He also has N
cages numbered 0,1,...,N−1
. Everyday he takes all his dogs out and walks them outside. When he is back
home, as dogs can’t recognize the numbers, each dog just randomly selects a cage
and enters it. Each cage can hold only one dog.
One day, Jerry noticed that
some dogs were in the cage with the same number of themselves while others were
not. Jerry would like to know what’s the expected number of dogs that are NOT in
the cage with the same number of themselves.
cases, T
. T
test cases follow.
Each test case contains only one number N
, indicating the number of dogs and cages.
1≤T≤105
1≤N≤105
#x: y”, where x
is the test case number (starting from 1) and y
is the expected number of dogs that are NOT in the cage with the same number of
itself.
y
will be considered correct if it is within an absolute or relative error of
10−6
of the correct answer.
1
2
Case #2: 1.0000000000
In the first test case, the only dog will enter the only cage. So the answer is 0.
In the second test case, if the first dog enters the cage of the same number, both dogs are in the cage of the same number,
the number of mismatch is 0. If both dogs are not in the cage with the same number of itself, the number of mismatch is 2.
So the expected number is (0+2)/2=1.
思路:和的期望等于期望的和;可以考虑每个位置对总期望的贡献,每个位置满足A[i]!=i有n-1种情况,满足条件的期望为(n-1)/n;
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
typedef vector<double> vec;
typedef vector<vec> mat;
const int N_MAX = ;
double n;
int T; int main() {
scanf("%d", &T);
int k = ;
while (T--) {
k++;
scanf("%lf",&n);
printf("Case #%d: %.10f\n",k,n-);
}
return ;
}
poj 6243 Dogs and Cages的更多相关文章
- A - Dogs and Cages HDU - 6243(组合数学)
题意:在1—n的数字,放入编号为1—n的框中,每个框只放一个数字,问数字与所放的框的编号不同的个数的期望值. 思路:在1—n中任选一个数字,设为k 那么 k 排到非k编号的框中的方案数为 n!-(n- ...
- Hdu-6243 2017CCPC-Final A.Dogs and Cages 数学
题面 题意:问1~n的所有的排列组合中那些,所有数字 i 不在第 i 位的个数之和除以n的全排,即题目所说的期望,比如n=3 排列有123(0),132(2),231(3),213(2),312(3) ...
- CCPC 2017-2018, Finals Solution
A - Dogs and Cages 水. #include <bits/stdc++.h> using namespace std; int t; double n; int main( ...
- 模拟赛小结:2017 China Collegiate Programming Contest Final (CCPC-Final 2017)
比赛链接:传送门 前期大顺风,2:30金区中游.后期开题乏力,掉到银尾.4:59绝杀I,但罚时太高卡在银首. Problem A - Dogs and Cages 00:09:45 (+) Solve ...
- poj 2761 Feed the dogs (treap树)
/************************************************************* 题目: Feed the dogs(poj 2761) 链接: http: ...
- POJ 2761 Feed the dogs(平衡树or划分树or主席树)
Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs ...
- POJ 题目2761 Feed the dogs(主席树||划分树)
Feed the dogs Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 16860 Accepted: 5273 De ...
- POJ 2761 Feed the dogs (主席树)(K-th 值)
Feed the dogs Time Limit: 6000MS Memor ...
- POJ 2761 Feed the dogs
主席树,区间第$k$大. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> ...
随机推荐
- mybatis association嵌套association的两级嵌套问题
今天遇到了一个双表连接查询以及自关联的问题,由于第一次遇到,所以在这记下,日后好查阅 针对一个表的关联属性本身也有自关联的情况下,可以用association嵌套association的方法来处理. ...
- 【思维题 线段树】cf446C. DZY Loves Fibonacci Numbers
我这种maintain写法好zz.考试时获得了40pts的RE好成绩 In mathematical terms, the sequence Fn of Fibonacci numbers is de ...
- 【数位dp】bzoj3131: [Sdoi2013]淘金
思路比较自然,但我要是考场上写估计会写挂:好像被什么不得了的细节苟住了?…… Description 小Z在玩一个叫做<淘金者>的游戏.游戏的世界是一个二维坐标.X轴.Y轴坐标范围均为1. ...
- python入门:BREAK 的用法 跳当前循环后,不再执行下面代码块
#!/urs/bin/env python # -*- coding:utf-8 -*- # BREAK 的作用 跳当前循环后,不再执行下面代码块 while True: ') break ') #w ...
- vue使用原生js实现滚动页面跟踪导航高亮
需要使用vue做一个专题页面. 滚动页面指定区域导航高亮. BetterScroll:可能是目前最好用的移动端滚动插件 如何自定义CSS滚动条的样式? 监听滚动页面事件,对比当前页面的位置与元素的位置 ...
- drf 频率组件 META字典详情
drf频率组件 什么是频率 控制用户对某个url的请求频率,比如一分钟之内,只能访问三次 自定义频率规则 1.取出访问者ip 2.判断当前ip在不在访问字典中: 不在,则添加进去,返回True; 3. ...
- leetcode-22-string
521. Longest Uncommon Subsequence I find the longest uncommon subsequence of this group of two strin ...
- Linux学习-什么是进程 (process)
触发 任何一个事件时,系统都会将他定义成为一个进程,并且给予这个进程一个 ID ,称为 PID,同时依据启发这个进程的用户与相关属性关系,给予这个 PID 一组有效的权限设定.从此以后,这 个 PID ...
- Flask-用户角色及权限
app/models.py class Role(db.Model): __tablename__ = 'roles' id = db.Column(db.Integer, primary_key=T ...
- 十分钟了解HTTPS协议
概念 HTTP协议上添加一层SSL/TLS协议进行加密,保证用户与web站点之间的数据传输时密文,而不是明文. PS:HTTPS协议 = HTTP协议 + SSL(Secure Sockets Lay ...