Editorial for Xổ số


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

Code mẫu của flashmt

#include<iostream>
#include<string>
using namespace std;

long long c(int x,int y)
{
     if (x>y) return 0;
     if (x==0) return 1;
     return c(x-1,y)*(y-x+1)/x;
}

int main()
{
    string s;
    int n;
    double x,y;
    while (1) 
    {
          cin >> s;
          if (s=="[END]") return 0;
          if (s=="[CASE]") 
          {
              cin >> n;
              x=c(5,n)*3125+c(3,n-1)*1250*n+c(2,n-1)*500*n;
              y=c(5,5*n);   
              cout << 1-x/y << endl;
          }
    }
    return 0;
}

Code mẫu của happyboy99x

#include<cstdio>

int main() {
    for(int n, t; scanf("%*s%d",&n) != EOF; ) {
      t = 5*n - 5;
      printf("%.17lf\n",n*(10*t*(t-1)/2+5*t+1)/(double)((long long)(t+1)*(t+2)*(t+3)*(t+4)*(t+5)/120));
    }
    return 0;
}

Code mẫu của ladpro98

var     a, b, m, n: int64;
        c: double;
        inp: text;
        s: string;
begin
        assign(inp,'');reset(inp);
        while not eof(inp) do begin
                readln(inp,s);
                if s = '[END]' then break;
                readln(inp,n);readln(inp);
                m := 5 * n - 5;
                a := 120 * (m * (m-1) + m) + 24;
                b := (m+1) * (m+2) * (m+3) * (m+4);
                c := a / b;
                writeln(c:0:11);
        end;
end.

Code mẫu của RR

#include <iostream>
#include <algorithm>
#include <iomanip>
#define FOR(i,a,b) for(int i=a; i<=b; i++)
using namespace std;

int debug=0;
char s[20];
int n;
long double c[6][6],a[511][6],f[111][6],gt[555];

void init() {
    FOR(i,0,5) {
        c[i][0]=1;
        FOR(j,1,i)
            c[i][j]=c[i-1][j-1]+c[i-1][j];
    }

    FOR(i,1,500) {
        a[i][0]=1.0;
        FOR(j,1,min(i,5))
            a[i][j]=a[i][j-1]*(i-j+1);
    }

    gt[0]=1;
    FOR(i,1,500) gt[i]=gt[i-1]*i;    
}

int main() {
    scanf("%s\n",&s);
    init();
    while (s[1]=='C') {
        scanf("%d",&n);
        f[0][0]=1.0;
        FOR(i,1,n)
        FOR(k,0,5) {
            f[i][k]=0;
            FOR(kk,max(k-2,0),k) {
                f[i][k]+=f[i-1][kk]*c[5-kk][k-kk]*a[5][k-kk]*a[5*n-5-(5*(i-1)-kk)][5-k+kk];
            }
        }        
        cout<<setprecision(15)<<(gt[5*n]-f[n][5])/gt[5*n]<<endl;
        scanf("%s\n",&s);
    }
    return 0;
}

Code mẫu của hieult

#include <stdio.h>
//#include <conio.h>

int main()
{
   // freopen("LOTT.inp","r",stdin);
    char s[10];
    long long n,m,d,k;
    while(gets(s)>0)
    {
        if(s[0]!='[')
            continue;
        else if(s[1]=='E')
            break;
        else
        {
            scanf("%lld",&n);
            if(n==1||n==2)
                printf("1.0\n");
            else
            {
                m = n*5;d=(m-1)*(m-2)*(m-3)*(m-4)*m/120;
                k = 125*n*(n-1)+125*n*(n-1)*(n-2)+n;
                printf("%.16lf\n",k*1./d);
            }
        }
    }
   // getch();
}

Code mẫu của ll931110

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int n;

int main()
{
//    freopen("lott.in","r",stdin);
//    freopen("lott.ou","w",stdout);
    string s;
    while (1)
    {
          cin >> s;
          if (s == "[END]") break;
          cin >> n;
//          cout << n;
          double c = 1.0;
          for (int i = 0; i < 5; i++) c*= (5 * n - i) / (i + 1.0) * 1.0;
          double c3 = 5.0 * n * (5 * n - 5) * (5 * n - 6);
          double c4 = n * (5 * n - 5) * 5.0;
          double c5 = n * 1.0;
          printf("%.9lf\n", (c3 + c4 + c5)/c);
    };
};

Code mẫu của skyvn97

#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
string s;
int n;
int main(void) {
    ios::sync_with_stdio(false);
    while (true) {
        cin >> s;
        if (s=="[END]") return 0;       
        cin >> n;
        printf("%.7lf\n",24.0*(125LL*n*(n-1)*(n-2)+100LL*n*(n-1)+25LL*n*(n-1)+n)/(1LL*n*(5*n-1)*(5*n-2)*(5*n-3)*(5*n-4)));
    }   
}

Code mẫu của khuc_tuan

F=[ 0.0,1.0,1.0,0.5004995004995005,0.2905056759545923,0.18831168831168832,0.13161551092585574,0.09705451095394169,0.07447933763723238,0.05893879234775434,0.04779210481602447,0.039528728762913,0.03323475257401247,0.02833125582332351,0.024437218696103304,0.021293626252144485,0.018719455095204597,0.016585117084676297,0.014795877828954968,0.013281189283099105,0.011987644167320162,0.010874212668378378,0.009908954314662415,0.00906670527071086,0.008327423942647239,0.007674989188542126,0.00709631499550928,0.006580689867749948,0.006119278042572384,0.005704738773363287,0.005330932792549047,0.004992693867686179,0.004685649464225555,0.0044060788129125054,0.004150799725544582,0.003917077692678838,0.0037025523881445976,0.003505177873047828,0.0033231736570587555,0.003154984421280131,0.002999246694153425,0.002854761141830804,0.002720469417499033,0.0025954347322278593,0.0024788254790646677,0.0023699013741218964,0.0022680016820733223,0.0021725351753470743,0.0020829715413143773,0.0019988340036656686,0.001919692965793805,0.0018451605175575437,0.0017748856739672053,0.0017085502364297964,0.0016458651852358157,0.0015865675267664305,0.0015304175310796165,0.001477196305597236,0.0014267036589595457,0.0013787562160567954,0.001333185751043936,0.0012898377099990138,0.001248569898964183,0.001209251316544779,0.0011717611131459912,0.0011359876613876159,0.001101827724328539,0.0010691857099140811,0.0010379730015809385,0.0010081073562572293,9.79512362113221E-4,9.521169493801174E-4,9.258549483834684E-4,9.006646896542007E-4,8.764886416005805E-4,8.532730817626102E-4,8.309677981382295E-4,8.095258174782203E-4,7.889031578023435E-4,7.690586027001621E-4,7.499534952523081E-4,7.315515496468653E-4,7.138186787755071E-4,6.967228362788472E-4,6.802338716734345E-4,6.643233973367226E-4,6.489646662536305E-4,6.341324595410415E-4,6.198029828665949E-4,6.059537709669546E-4,5.925635995497607E-4,5.796124039338542E-4,5.670812038451472E-4,5.549520338415767E-4,5.43207878890715E-4,5.318326146684996E-4,5.208109521877798E-4,5.10128386401491E-4,4.997711484577105E-4,4.897261613130418E-4,4.7998099843704644E-4]
while True:
    s = raw_input().split(chr(13))[0]
    if s == "[END]":
        break
    n = int(raw_input().split(chr(13))[0])
    raw_input()
    print "%.7f" % (F[n])

Comments

Please read the guidelines before commenting.


There are no comments at the moment.