Cod sursa(job #1252847)

Utilizator Alex_dudeDudescu Alexandru Alex_dude Data 31 octombrie 2014 13:41:59
Problema Dezastru Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <cstdio>
#include <algorithm>
#define nmax 26

double probabilitate,v[nmax],loc;
FILE *f1=fopen("dezastru.in","r"),*f2=fopen("dezastru.out","w");
int n,m,nr,i;
int main()
{
   fscanf(f1,"%d%d",&n,&m);
   for(i=0;i<n;i++)
    fscanf(f1,"%lf",&v[i]);
   std::sort(v,v+n);
    do
   {   loc=1.0;
       for(i=0;i<m;i++)
       loc*=v[i];
       probabilitate+=loc;
       nr++;
   }while(std::next_permutation(v,v+n));
   fprintf(f2,"%lf",probabilitate/nr);
  return 0;
}

//Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.