Codeforces Round #293 (Div.2) 小记

来源:互联网 发布:网络信息发布规范 编辑:程序博客网 时间:2024/06/01 08:08

A.过pre,然后被hack了。而且到最后都没改过来- -

题意:

给出两个串,s和t,保证字典序s<t且两串长度相同。构造一个串使得其字典序s<str<t。

str和s、t长度相同。


思路:

从后面开始找到第一个不是'z'的字母,将其换成字母表中后一个字母。

再把找到字母后面的字母全部换成'a'。如果此时构造出的字符串不满足<t则输出没有这种满足条件的串。


#include<cstdio>#include<cstring>#include<iostream>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cstdlib>#include<cmath>#include<vector>#include<queue>#include<map>using namespace std;typedef long long ll;char s[110],t[110],a[110];int main(){    while(~scanf("%s%s",s,t))    {        memset(a,0,sizeof(a));        strcpy(a,s);        int len = strlen(s);        int i=len-1;        while(i>=0 && s[i]=='z') i--;        a[i] = (a[i]-'a'+1)+'a';        for(int j=i+1;j<len;j++)            a[j] = 'a';        if(strcmp(a,t)<0)printf("%s\n",a);        else printf("No such string\n");    }    return 0;}/*abaacaans:abb*/

B.开始把题意读错了,不过读懂后很快就过了。此处略。

C.统计的时候明明开始有意识的把统计变量c定义成了long long。后来不知中了什么邪,交之前全改成int。

过了pre就没看了。结果爆long long 。哭瞎。。。。= =

D.概率dp  前面时间用了好多,A被hack后就有点慌。此题没能很快建模。

D. Ilya and Escalator
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor.

Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probabilityp, or the first person in the queue doesn't move with probability(1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him.

Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator aftert seconds.

Your task is to help him solve this complicated task.

Input

The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000,0 ≤ p ≤ 1). Numbers n and t are integers, numberp is real, given with exactly two digits after the decimal point.

Output

Print a single real number — the expected number of people who will be standing on the escalator aftert seconds. The absolute or relative error mustn't exceed10 - 6.

Sample test(s)
Input
1 0.50 1
Output
0.5
Input
1 0.50 4
Output
0.9375
Input
4 0.20 2
Output
0.4

题意:

一条队中有n个人,每秒钟队头的人可以选择乘不乘车。他选择乘车的概率为p。每秒钟只能有一个人上车,第i个人

选择的条件是前i-1个人(第1~i-1个)都已经在车上。问t秒后车上人数的期望。


建模:

f[i][j]表示i秒后车上有j个人的概率。

当j=n时,f[i+1][j] += f[i][j]

否则,f[i+1][j] += f[i][j]*(1-p),f[i+1][j+1] += f[i][j]*p

最后的期望 = sum(j*f[t][j]) (0<=j<=n)


#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cstdlib>#include<cmath>#include<vector>#include<queue>#include<map>using namespace std;typedef long long ll;double f[2010][2010];int main(){    double p;    int n,t;    while(~scanf("%d%lf%d",&n,&p,&t))    {        memset(f,0,sizeof(f));        f[0][0] = 1.0;        for(int i=0;i<t;i++)        {            for(int j=0;j<n;j++)            {                f[i+1][j+1] += f[i][j]*p;                f[i+1][j] += f[i][j]*(1-p);            }            f[i+1][n] += f[i][n];        }        double ans = 0;        for(int j=0;j<=n;j++)            ans += f[t][j]*j;        printf("%.8lf\n",ans);    }    return 0;}



0 0