Codeforces Round #185 (Div. 2)--A,B

A题。

题目链接:http://codeforces.com/contest/312/problem/A

分析:分三类。1:首有“miao.”,末无“lala.”2:首无,末有。3:首末同有或首末同无。

由代码的小失误,较晚AC这题哭.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
    int n,l;
    int flag1,flag2;
    char str[105];
    cin>>n;
    getchar();
    for(int i=1;i<=n;i++)
    {
        flag1=1;
        flag2=1;
        gets(str);
        l=strlen(str);
        if(str[0]=='m'&&str[1]=='i'&&str[2]=='a'&&str[3]=='o'&&str[4]=='.')
        flag2=-1;
        if(str[l-1]=='.'&&str[l-2]=='a'&&str[l-3]=='l'&&str[l-4]=='a'&&str[l-5]=='l')
        flag1=-1;
        if(flag1*flag2==1)
        printf("OMG>.< I don't know!\n");
        else
        {
            if(flag1==-1)
            printf("Freda's\n");
            if(flag2==-1)
            printf("Rainbow's\n");
        }
    }
}

B题。

题目链接:http://codeforces.com/contest/312/problem/B

比赛时没看懂题目,但看到过了人的挺多的,再看第一组测试数据是2/3,于是便在凑数据,但最终还是没过。

分析:B题是个求数学期望的题(都忘了#+#)

这个模型是无穷等比数列求和
甲获胜的概率=甲第一次获胜+甲第二次获胜+甲第三次获胜+....(加到无穷)

然后利用无穷等比数列求和公式sn=a₁/(1-q)=P/(P+Q-PQ)
注:无穷等比数列的公比q=(1-p)(1-q)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
    double a,b,c,d;
    double P,Q;
    scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
    P=a/b;
    Q=c/d;
    printf("%lf\n",P/(1-(1-P)*(1-Q)));
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值