UVA 10375 - Choose and divide
来源:互联网 发布:闪凌网络是真的吗 编辑:程序博客网 时间:2024/05/17 16:57
这道题要求C(p,q)/C(r,s);可以根据组合数公式,由于中间数字较大,容易溢出,所以可以采用边乘边除,但是仍然好像会溢出,所以最后听别人说可以先取对数,然后最后转化回来就好了,不过要用long double
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
int main()
{
long p,q,r,s,i;
long double res;//此处用long double才可以
while(scanf(\"%ld%ld%ld%ld\",&p,&q,&r,&s)==4)
{
res=0;
if(q<p-q)q=p-q;
if(s<r-s)s=r-s;
if(p>r)
for(i=r+1;i<=p;i++)res+=log(i);
else
for(i=p+1;i<=r;i++)res-=log(i);
if(s>q)
for(i=q+1;i<=s;i++)res+=log(i);
else
for(i=s+1;i<=q;i++)res-=log(i);
if(r-s>p-q)
for(i=p-q+1;i<=r-s;i++)res+=log(i);
else
for(i=r-s+1;i<=p-q;i++)res-=log(i);
res=exp(res);
printf(\"%0.5Lf\\n\",res);
}
return 0;
}
- UVA 10375 - Choose and divide
- uva 10375 - Choose and divide
- UVA - 10375 Choose and divide
- UVa:10375 Choose and divide
- uva 10375 Choose and divide
- UVA 10375 Choose and divide
- Choose and divide - UVa 10375
- UVA - 10375 Choose and divide
- UVA - 10375 Choose and divide
- UVA - 10375 Choose and divide
- UVa 10375 - Choose and divide
- uva 10375 Choose and divide
- UVa 10375 Choose and divide
- UVA 10375 Choose and divide
- UVa 10375 - Choose and divide
- UVA - 10375 Choose and divide
- uva 10375Choose and divide
- UVA 10375 Choose and divide
- UVA 10717 - Mint
- UVA 11069 - A Graph Problem
- UVA 10943 - How do you add
- UVA 10491-Cows and Cars
- UVA 10706 - Number Sequence
- UVA 10375 - Choose and divide
- UVA 10161-Ant on a Chessboard
- UVA 10177 - (234)-D SqrRectsCubesBoxes
- UVA 10182 - Bee Maja
- UVA 10195 - The Knights Of The Round Table
- UVA 10209 - Is This Integration
- UVA 10215 - The LargestSmallest Box ...
- UVA 10310 - Dog and Gopher
- UVA 439 - Knight Moves