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> ...
随机推荐
- 廖老师JavaScript教程高阶函数-sort用法
先来学习一个新词:高阶函数 高阶函数英文叫Higher-order function.那么什么是高阶函数? JavaScript的函数其实都指向某个变量.既然变量可以指向函数,函数的参数能接收变量,那 ...
- iOS 证书、真机调试、发布 App Store
之前对iOS的证书弄的很不清楚,Xcode里面也有各种证书,作为一只有强迫症的巨蟹座,这是不能忍的 趁着准备发布自己的第一个app,梳理一下这块内容 主要参考了这几篇文章: iOS开发:创建真机调试证 ...
- cocos2dx 单张图片加密
cocos2dx 已经封装好读取加密的prv文件的方法,打开texturepacker,导入一张图片,在content protection中写入密钥,在texture format中选择prv格式 ...
- 【思维题 状压dp】APC001F - XOR Tree
可能算是道中规中矩的套路题吧…… Time limit : 2sec / Memory limit : 256MB Problem Statement You are given a tree wit ...
- 第一课 项目的介绍 Thinkphp5第四季
学习地址: https://study.163.com/course/courseLearn.htm?courseId=1004887012#/learn/video?lessonId=1050543 ...
- 使用 Python 编写登陆接口
# 使用 Python 编写登陆接口# Create Date: 2017.10.31 Tuesday# Author: Eric Zhao# -*- coding:utf-8 -*-'''编写登陆接 ...
- python-闭包函数和装饰器
目录 闭包函数 什么是闭包? 两种为函数传参的方式 使用参数的形式 包给函数 闭包函数的应用 闭包的意义: 装饰器 无参装饰器 什么是装饰器 为什么要用装饰器 怎么用装饰器 完善装饰器 闭包函数 什么 ...
- BFS:UVa1590-IP Networks (子网掩码相关知识)
IP Networks Alex is administrator of IP networks. His clients have a bunch of individual IP addresse ...
- poj 1328 安雷达问题 贪心算法
题意:雷达如何放置?在xoy二维平面坐标系里面,x轴上方的为岛屿,x轴下方的是雷达要放到位置,如何放使得雷达放的最少? 思路 肯定放在x轴上减少浪费是最好的选择 什么情况下,雷达无法到达呢?--以这个 ...
- 浅谈抓取网页数据(奉上Demo)
Demo源码 背景 曾经在公司做过一个比价系统,就是抓取其它网站上商品的价格并和自己公司的商品进行对应,然后展示出来,给pm提供一个定价的参考.后来,有同事的朋友在找工作的时候,猎头让其做一个抓取去哪 ...