Cod sursa(job #1612724)

Utilizator tothalToth Alexandru tothal Data 24 februarie 2016 23:38:47
Problema Dezastru Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <fstream>
#include <iomanip>
using namespace std;
ifstream fin("dezastru.in");
ofstream fout("dezastru.out");
int n,k,nr,n_k,cn,ck;
float s;
float v[30];
int x[30];
void calcnr()
{int aux=1;
    for(int i=1;i<=n;i++)
    {aux*=i;
       if(i==n-k && n-k>0)
         n_k=aux;
        if(i==n)
           cn=aux;
        if(i==k)
        ck=aux;
    }
    nr=cn/ck;
    nr=nr/n_k;
}
void calcs()
{
    for(int i=1;i<n;i++)
    {
                float sp=0;
        for(int j=i+1;j<=n;j++)
        {
            sp+=(float)v[j];
        }
        sp*=v[i];
        s+=sp;
    }
}
int main()
{
    fin>>n>>k;
    for(int i=1;i<=n;i++)
        fin>>v[i];
    calcnr();
    calcs();
    fout<<setprecision(6)<<(float)s/nr;
}