2014 NEUACM 新星赛



1481: Sister Wang

时间限制: 1 Sec   内存限制: 256 MB
提交: 514   解决: 115
[ 提交][ 状态][ 讨论版]

题目描述

Do you know Sister Wang?

Sister Wang is goddess and many diaosi want to know her phone number. Sister Wang doesn’t tell them her number directly. She tells them a string, contains letters,


 digits and symbols,but no blanks. And her phone number is in the string. Fushuai knows how to get the phone number. He delete the letters and symbols from the 

string, so that he gets some digits, and then he sort the digits in ascending order. In this way, Fushuai succeeds in calling Sister Wang.

输入

There are several cases. Each cases contains a string L(1<= length(L)<=20).

输出

Output Sister Wang’s phont number.

样例输入

Sist1e2r3w4a5ng

样例输出

12345

提示

来源

新星赛2014

[ 提交][ 状态][ 讨论版]

1484: Hengheng eat noodles

时间限制: 1 Sec   内存限制: 256 MB
提交: 15   解决: 12
[ 提交][ 状态][ 讨论版]

题目描述

As we all know,Hengheng(big cow),very look forward to meizi and he often declare that he want to find a meizi.As Hengheng’s admirer, Jiajia decides to help Hengheng to achieve his dream in Christmas Day. In this day, Jiajia asks Hengheng to eat noodles with a pretty meizi(don’t ask why Jiajia didn’t chase this pretty meizi). When eating noodles, Hengheng is so excited that he wants the qq of the meizi. However, a unlucky thing happen.The pretty meizi says she won’t give Hengheng her qq unless Hengheng can solve her question. Hengheng promise without hesition.The pretty meizi picks up a noodle and say with sexy voice, “We all know a noodle has two ends,and now I has n noodles, so there are 2*n ends at all. Out of interest,I will link these ends randomly,and then I wonder the mathematical expectation of the circle I could get.” Although Hengheng is big cow, he can’t wait to get the qq so he can’t think as long as he see the pretty. So he ask Jiajia to solve the problem for him. Luckily,after 1000 ms,Jiajia give the right answer. And Hengheng got the qq successfully. Now, if you are Jiajia, could solve the problem within 1000 ms and help Hengheng get the qq.

输入

The first line is a integer t,indicate the number of cases.(t<=10)
For each case follow,there is a integer n,imply the amount of noodles.(n<=10^6)

输出

For each case, print a double E,represent the mathematical expectation.(E retain 6 decimal)

样例输入

3
1
2
4

样例输出

1.000000
1.333333
1.676190

提示

2014 NEUACM 新星赛_第1张图片


来源

新星赛2014

[ 提交][ 状态][ 讨论版]

题意:求n条面条围成圆圈的数学期望。

解题思想:n条面条总共有2n个端点。可看做n-1条面条增加一条面条,对于增加的这条面条,我们随便选取一个端点,总共有2n-1个端点可以与之结合:
1.对于第一种情况,只能跟自己另一条边组合,故第一种情况圆圈数加一,这种概率为p1=1/(2n-1)
2.除了第一种情况就是第二种情况,圆圈数不变,这种概率为p2=(2n-2)/(2n-1)

数学规律递推公式推导(E'代表连加符号西格玛,S表示圆圈数,p表示对应的概率):
exp(n-1)=E'SjPj
exp(n)=E'(Sj+1)PjP1+E'SjPjP2
           =(E'SjPj+E'Pj)P1+E'SjPjP2
           =(exp(n-1)+1)P1+exp(n-1)P2
           =(exp(n-1)+1)*1/(2n-1)+exp(n-1)*(2n-2)/(2n-1)


AC代码:



?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
double e[1000001];
int main()
{
     int t,i,n;
     e[1]=1.000000;
     for (i=2;i<=1000001;i++)
     {
         e[i]=(e[i-1]+1.0)/(2*i-1)+e[i-1]*(2*i-2)/(2*i-1);
     }
     scanf ( "%d" ,&t);
     while (t--)
     {
         scanf ( "%d" ,&n);
         printf ( "%lf\n" ,e[n]);
     }
     return 0;
}
/**************************************************************
     Problem: 1484
     User: 1307122118
     Language: C++
     Result: 正确
     Time:119 ms
     Memory:9064 kb
****************************************************************/




?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
double e[1000001];
int main()
{
     int t,i,n;
     e[1]=1.000000;
     for (i=2;i<=1000001;i++)
     {
         e[i]=(e[i-1]+1.0)/(2*i-1)+e[i-1]*(2*i-2)/(2*i-1);
     }
     scanf ( "%d" ,&t);
     while (t--)
     {
         scanf ( "%d" ,&n);
         printf ( "%lf\n" ,e[n]);
     }
     return 0;
}
/**************************************************************
     Problem: 1484
     User: 1307122118
     Language: C++
     Result: 正确
     Time:119 ms
     Memory:9064 kb
****************************************************************/

你可能感兴趣的:(算法,数学,ACM)