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;
}