跳过正文
  1. Posts/

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,开心。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年02月02日 星期二 03时32分39秒
 4File Name :code/cf/problem/476B.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;
33string s1,s2;
34int len;
35int c[20][20];
36void pre()
37{
38    ms(c,0);
39    c[1][1] = 1;
40    c[1][2] = 1;
41    c[2][1] = 1;
42    c[2][2] = 2;
43    c[2][3] = 1;
44    for ( int i =3 ; i  <=15 ; i++)
45	for ( int j = 0 ; j <= i ; j++)
46	    c[i][j+1] = c[i-1][j+1]+c[i-1][j];
47}
48int main()
49{
50	#ifndef  ONLINE_JUDGE
51	freopen("code/in.txt","r",stdin);
52  #endif
53	pre();
54
55	cin>>s1>>s2;
56	len = s1.length();
57	int a=0,b=0;
58	for ( int i = 0 ; i < len ; i++)
59	{
60	    if (s2[i]=='?') a++;
61	    if (s1[i]=='+') b++;
62		else b--;
63	    if (s2[i]=='+') b--;
64		else if (s2[i]=='-') b++;
65	}
66//	cout<<"a:"<<a<<endl;
67//	cout<<"b:"<<b<<endl;
68	if (a==0)
69	{
70	    if (b==0) puts("1");
71	    else puts("0");
72	}
73	else
74	{
75	    double ans = c[a][(a-b)/2+1]*1.0;
76	    for ( int i = 1 ; i <= a ; i ++) ans *=0.5;
77	    printf("%.11lf\n",ans);
78	}
79
80  #ifndef ONLINE_JUDGE
81  fclose(stdin);
82  #endif
83    return 0;
84}

相关文章

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的两个式子.。。 思路:数学上这个方程貌似不可解。。? 所以只能枚举一下==。。。注意精度问题把。。。

uva 846 Steps

·2 分钟
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=787 题意:从x增加到y,第一步和最后一步步长只能是1,其他步一定可以是上一步减一,和上一步相等,或者上一步步长加一,三种情况,且步长恒为正。问从x到y最少需要的步数。

uva 10025 The ? 1 ? 2 ? ... ? n = k problem

·1 分钟
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=966 题意:?1?2?3?4…?n=k,把每个?替换成+或者-,找到最小的n使得式子成立。 题意:这道题最关键的一点是。如果s1=1+2+3+.,x+..+n>=k (所有数取正数),那么一定有s2=1+2+3+..-x+..+n=k