B - Candy
2013-04-24 12:40
120 查看
B -
Candy
卡时间卡的好厉害啊
枚举公式OK
#include<cstdio>
#include<cmath>
int main()
{
int n,id=0;
double p,q,cp,cq;
while(~scanf("%d%lf",&n,&p))
{
q=1-p;
cq=cp=1;
int i,last=n+1;
double ans=0;
for(i=0;i<n;i++)
{
if(i)
{
cp = cp * (n+i) * p / i;
cq = cq * (n+i) * q / i;
while(cp>n || cq>n)
{
cp *= q;
cq *= p;
last --;
}
}
ans += (n-i) * cq * pow(p,last);
ans += (n-i) * cp * pow(q,last);
}
printf("Case %d: %.6f\n",++id,ans);
}
return 0;
}
Candy
卡时间卡的好厉害啊
枚举公式OK
#include<cstdio>
#include<cmath>
int main()
{
int n,id=0;
double p,q,cp,cq;
while(~scanf("%d%lf",&n,&p))
{
q=1-p;
cq=cp=1;
int i,last=n+1;
double ans=0;
for(i=0;i<n;i++)
{
if(i)
{
cp = cp * (n+i) * p / i;
cq = cq * (n+i) * q / i;
while(cp>n || cq>n)
{
cp *= q;
cq *= p;
last --;
}
}
ans += (n-i) * cq * pow(p,last);
ans += (n-i) * cp * pow(q,last);
}
printf("Case %d: %.6f\n",++id,ans);
}
return 0;
}
相关文章推荐
- 我想要凯蒂-I Want Candy
- poj 3038 Children of the Candy Corn bfs dfs
- pku 3083 Children of the Candy Corn
- HDU 1034 Candy Sharing Game(水模拟)
- POJ 3083 Children of the Candy Corn dfs+bfs
- 1052. Candy Sharing Game
- 模拟_题目1145:Candy Sharing Game
- hdu4465 Candy(快速排列组合+概率)
- Children of the Candy Corn
- Candy
- LeetCode:Candy
- CODE 132: Candy
- Leetcode: Candy
- LeetCode | Candy
- Codeforces 400C Inna and Huge Candy Matrix
- [LeetCode] Candy
- Leetcode | Candy
- hust 1422 Candy!
- POJ 3083 - Children of the Candy Corn
- [LeetCode]—Candy 分糖果问题