Knots

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 250    Accepted Submission(s): 173

Problem Description
An even number N of strands are stuck through a wall. On one side of the wall, a girl ties N/2 knots between disjoint pairs of strands. On the other side of the wall, the girl's groom-to-be also ties N/2 knots between disjoint pairs of strands. You are to find the probability that the knotted strands form one big loop (in which case the couple will be allowed to marry). 
For example, suppose that N = 4 and you number the strands 1, 2, 3, 4. Also suppose that the girl has created the following pairs of strands by tying knots: {(1, 4), (2,3)}. Then the groom-to-be has two choices for tying the knots on his side: {(1,2), {3,4)} or {(1,3), (2,4)}.
 
Input
The input file consists of one or more lines. Each line of the input file contains a positive even integer, less than or equal to 100. This integer represents the number of strands in the wall.
 
Output
For each line of input, the program will produce exactly one line of output: the probability that the knotted strands form one big loop, given the number of strands on the corresponding line of input. Print the probability to 5 decimal places.
 
Sample Input
4
20
 
Sample Output
0.66667
0.28377
 

题解:画图+模拟;题意是绑绳,新娘新浪各自把N个绳,两两绑在一块,变成N/2个绳子,如果新娘新浪绑的绳子能组成大圆就能结婚,问能结婚的概率;

如果两个,1 2 2 1,必然成环;是1;4个,相当于两个线段 一:1-2  3-4;二:1-3  2-4或者三:1-4 2-3;总共三种情况,对于每一种情况,另两个都能与他成环;所以是2/3;

6个,三个线段;- - -;看看就是4/5;由于1-2 3-4 5-6;也可以是1-2 3-5 4-6;所以也要考虑 - -的匹配情况所以要乘上两个线段的情况;4/5*2/3;。。。。。

最后可以推出规律dp[i] = dp[i - 1]*(i-2)/(i-1);

代码:

extern "C++"{
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
typedef long long LL;
void SI(int &x){scanf("%d",&x);}
void SI(double &x){scanf("%lf",&x);}
void SI(char *x){scanf("%s",x);}
//void SI(LL &x){scanf("%lld",&x);} void PI(int &x){printf("%d",x);}
void PI(double &x){printf("%lf",x);}
void PI(char *x){printf("%s",x);}
//void PI(LL &x){printf("%lld",x);} }
int main(){
double dp[];
dp[] = ;
for(int i = ;i <= ; i += ){
dp[i] = dp[i - ] * (i - )/(i - );
}
int N;
while(~scanf("%d",&N)){
printf("%.5lf\n",dp[N]);
}
return ;
}

Knots(找规律)的更多相关文章

  1. hdu 3951 - Coin Game(找规律)

    这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...

  2. HDU 5703 Desert 水题 找规律

    已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这 ...

  3. hdu4952 Number Transformation (找规律)

    2014多校 第八题 1008 2014 Multi-University Training Contest 8 4952 Number Transformation Number Transform ...

  4. CF456B Fedya and Maths 找规律

    http://codeforces.com/contest/456/problem/B CF#260 div2 B Fedya and Maths Codeforces Round #260 B. F ...

  5. hdu 4731 2013成都赛区网络赛 找规律

    题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举

  6. 找规律 Codeforces Round #290 (Div. 2) A. Fox And Snake

    题目传送门 /* 水题 找规律输出 */ #include <cstdio> #include <iostream> #include <cstring> #inc ...

  7. 找规律 ZOJ3498 Javabeans

    Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n boxes of javabeans. ...

  8. C基础之递归(思想很重要,学会找规律)

    递归思想的条件:1.函数自己调用自己 2.函数必须有一个固定的返回值(如果没有这个条件会发生死循环) ----规律很重要 简单递归题目一: 设计一个函数计算一个整数的n次方,比如2的3次方,就是8 步 ...

  9. BZOJ-1228 E&D 博弈SG+找啊找啊找规律

    讨厌博弈,找规律找半天还是错的.... 1228: [SDOI2009]E&D Time Limit: 10 Sec Memory Limit: 162 MB Submit: 666 Solv ...

随机推荐

  1. c++容器使用总结(转载)

    目录 ==================================================== 第一章 容器 第二章 Vector和string 第三章 关联容器 第四章 迭代器 第五 ...

  2. 【POJ 2010 Moo University-Financial Aid】优先级队列

    题目链接:http://poj.org/problem?id=2010 题意:C只牛犊,各有自己的分数score和申请的补助aid,现要选出N只(N为奇数),使得其aid的总和不超过F,且按score ...

  3. openssl CA 自签证书,阿里云配置tomcat https

    <一,openssl CA自签发证书> 1,生成私钥 openssl genrsa 1024 > private.key;

  4. kiki's game

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: ...

  5. CATransform3D参数的意义

    经常忘记CATransform3D各参数的意思,记下来好好理解下   struct CATransform3D { CGFloat m11(x缩放),m12(y切变),m13(旋转),m14(); C ...

  6. Oracle SQL函数之数学函数

    Oracle SQL函数之数学函数 ABS(x) [功能]返回x的绝对值 [参数]x,数字型表达式 [返回]数字 SQL> SELECT ABS(),ABS(-) FROM DUAL; ABS( ...

  7. [python笔记][第二章Python序列-list]

    2016/1/27学习内容 第二章 Python序列-list list常用操作 list.append(x) list.extend(L) list.insert(index,x) list.rem ...

  8. 通用线程:POSIX 线程详解,第 3 部分 条件互斥量(pthread_cond_t)

    使用条件变量提高效率 本文是 POSIX 线程三部曲系列的最后一部分,Daniel 将详细讨论如何使用条件变量.条件变量是 POSIX 线程结构,可以让您在遇到某些条件时“唤醒”线程.可以将它们看作是 ...

  9. HDU 1068 - Girls and Boys

    求一个集合最多几个人,其之间任意两人没有暧昧关系. 二分图匹配 最大独立集 = 总点数 - 最大匹配数 匈牙利算法 因为每个同学都在二分图的两侧 当 A与B匹配时,B与A也匹配 所以 所求的最大匹配数 ...

  10. W - Bitset(第二季水)

    Description Give you a number on base ten,you should output it on base two.(0 < n < 1000)      ...