Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
what's wrong? (code here)#include<math.h> #include<stdio.h> double logab(int beg, int end) { __int64 static max = pow(10.0,18); double r = 0.0; while(beg<=end) { __int64 temp = 1; while(((double)temp)*beg<max && beg<=end) temp *= beg++; r += log(temp); } return r; } double pqrs(int p,int q,int r,int s) { int pb = (q<p/2)?q:p-q; int rb = (s<r/2)?s:r-s; double ex = 0; if(p>r) { if(p-pb<r-rb) ex = logab(r+1,p)+logab(p-pb+1,r-rb); else ex = logab(r+1,p)-logab(r-rb+1,p-pb); } else { if(p-pb>r-rb) ex = -logab(p+1,r)-logab(r-rb+1,p-pb); else ex = -logab(p+1,r)+logab(p-pb+1,r-rb); } if(rb<pb) ex -= logab(rb+1,pb); else ex += logab(pb+1,rb); return exp(ex); } int main() { int p,q,r,s; while (scanf("%d%d%d%d",&p,&q,&r,&s)==4) { double R = pqrs(p,q,r,s); if(R<1000000000) printf("%.5f\n",R); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator