跳过正文
  1. Posts/

codeforces 312 B. Archer

·2 分钟
目录
http://codeforces.com/problemset/problem/312/B
#

题意:两个人比赛射箭,先射的人射中的概率是a/b,后射的人射中的概率是c/d,问先射的人赢的概率。 思路:应该叫条件概率。。。? 不过我们可以用古典概型的思维想。每射一次看成一个点,射中的点用白色表示,没有射中的用黑色表示。如果两个人第i次都没有射中,那么就要继续第i+1 轮,而第i+1轮和之前的每一轮是独立的。等于重复这个过程。所以古典概型的样本总量应该减去宝石两个人都没有射中的点的个数,为bd-(b-a)(d-c),整理为bc+ad-a*c,设为n.要想第一个人赢,那么对于某一次,只要不是第一个人没射中,第二个人射中这种情况,就都是第一个人赢。而第一个人没射中的事件数为b-a,第二个人射中的事件数为c,总数为(b-a)*c,所以答案为(n-(b-a)*c)/n

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年02月02日 星期二 15时57分06秒
 4File Name :code/cf/518D.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=2E3+7;
34int n,t;
35double p;
36double dp[N][N];
37int main()
38{
39	#ifndef  ONLINE_JUDGE
40	freopen("code/in.txt","r",stdin);
41  #endif
42	ms(dp,0);
43	dp[0][0] = 1;
44	cin>>n>>p>>t;
45	for ( int i = 0 ; i <= t ; i++)
46	{
47	    for ( int j = 0 ; j <= n ; j++)
48	    {
49		if (j==n)
50		{
51		    dp[i+1][j]+=dp[i][j];
52		}
53		else
54		{
55		    dp[i+1][j+1]+=dp[i][j]*p;
56		    dp[i+1][j]+=dp[i][j]*(1-p);
57		}
58	    }
59	}
60	double ans = 0 ;
61	for ( int j = 1 ; j <= n ; j++)
62	    ans +=j*dp[t][j];
63
64	printf("%.12f\n",ans);
65
66  #ifndef ONLINE_JUDGE
67  fclose(stdin);
68  #endif
69    return 0;
70}

相关文章

codeforces 453 A. Little Pony and Expected Maximum

·1 分钟
http://codeforces.com/problemset/problem/453/A 题意:m面筛子,每面点数出现的概率相同,连续投掷n次,问出现的最大值的数学期望。 思路:手写样例。。。发现答案为 。。。记得把(1/m)^n放进去。

codeforces 476 B. Dreamoon and WiFi

·2 分钟
http://codeforces.com/problemset/problem/476/B 题意:给出两个长度相等-且不超过10的字符串,串1只包含‘-’,’+‘。按照‘+’为1,‘-’为-1累加可以得到一个值。串2还包含若干‘?’,代表该处的值不确定,且为’+‘和’-‘的概率相等,都是0.5.问串2的值和串1相等的概率。 思路:我们可以扫一遍得到‘?’的个数和两个式子的差值。设问号个数为a,差值为b,那么在a个问号中需要有(a-b)/2个为‘+’(容易知道,a,b一定奇偶性相同,所以a-b一定能被2整除),根据超几何分布,概率为 c[a][(a-b)/2]*(1/2)^a; 写的时候可以先打个组合数的表。1A,开心。

codeforces #341 div2 C. Wet Shark and Flowers

·3 分钟
http://codeforces.com/contest/621/problem/C C. Wet Shark and Flowers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too.

uva 10916 Factstone Benchmark

·1 分钟
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=1857 题意:计算最大的n,满足n!/* *********************************************** Author :111qqz Created Time :2016年01月29日 星期五 19时49分25秒 File Name :code/uva/10916.cpp ************************************************ */

uva 107 The Cat in the Hat

·1 分钟
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=43 题意:其实就是给了两个式子。。。(N+1)^h=a,N^h=b,a,b已知,然后求关于N的两个式子.。。 思路:数学上这个方程貌似不可解。。? 所以只能枚举一下==。。。注意精度问题把。。。