Advertisement
Guest User

Untitled

a guest
May 4th, 2013
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int abs(int a){
  5.     return (a>0)?a:-a;
  6. }
  7.  
  8. ofstream fout("outt.txt");
  9.  
  10. int heap[10001];
  11. int T,n,x,y;
  12. int main(){
  13.     heap[0]=1;
  14.     for(int i=1;i<=10000;i++){
  15.         heap[i]=heap[i-1]+4*i+1;
  16.     }
  17.     cin>>T;
  18.     fout.precision(10);
  19.     fout<<fixed;
  20.     for(int g=1;g<=T;g++){
  21.         cin>>n>>x>>y;
  22.         if(abs(x)+y==0){
  23.             fout<<"Case #"<<g<<": "<<1<<endl;
  24.             continue;
  25.         }
  26.         if(heap[(abs(x)+y)/2-1]>=n){
  27.             fout<<"Case #"<<g<<": "<<0<<endl;
  28.             continue;
  29.         }
  30.         if(heap[(abs(x)+y)/2]<=n){
  31.             fout<<"Case #"<<g<<": "<<1<<endl;
  32.             continue;
  33.         }
  34.         if(x==0){
  35.             fout<<"Case #"<<g<<": "<<0<<endl;
  36.             continue;
  37.         }
  38.         n-=heap[(abs(x)+y)/2-1];
  39.         if(n>abs(x)+2*y){
  40.             fout<<"Case #"<<g<<": "<<1<<endl;
  41.             continue;
  42.         }
  43.         long double p=1.0,sl=0;
  44.         for(int i=1;i<=n;i++){
  45.             if(i<y+1){
  46.                 p*=(long double)(n-i+1);
  47.                 p/=i;
  48.             }
  49.             p/=2;
  50.         }
  51.         for(int i=1;i<=n;i++){
  52.             if(i>=y+1){
  53.                 p*=(long double)(n-i+1);
  54.                 p/=i;
  55.                 sl+=p;
  56.             }
  57.            
  58.         }
  59.         fout<<"Case #"<<g<<": "<<sl<<endl;
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement