Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Simulador1X2 - Hector Ratia - Septiembre 2010
- */
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <iomanip>
- using namespace std;
- double porcentajes[14][3];
- double sumas[14][3];
- double porcentajeslae[14][3];
- int simulada[14];
- int simuladas;
- double unos[15];
- double equis[15];
- double doses[15];
- double var[15];
- double col1[15];
- double col2[15];
- double col3[15];
- int c1;
- int cx;
- int c2;
- int ac1;
- int ac2;
- int ac3;
- int acertantes;
- double probabilidad;
- double probreal;
- double probtotal=0;
- double premio;
- //double liston=30000;
- double liston[]={0,5000,10000,15000,20000,25000,30000,35000,40000,50000,60000,70000,80000,90000,100000,125000,150000,175000,200000,250000,300000,400000,500000};
- double premiomedio=0;
- //bool LAE=false;
- int recaudacion=13000000;
- char c;
- double aux;
- string linea;
- bool fin=false;
- int auxi;
- string col1s,col2s,col3s;
- int main()
- {
- int listones=sizeof(liston)/sizeof(double);
- int caras[listones];
- double probcaras[listones];
- ifstream archivolectura;
- ifstream archivolectura2;
- archivolectura.open("bet.txt");
- archivolectura2.open("lae.txt");
- for(int i=0; i<14; i++){
- archivolectura >> porcentajes[i][0];
- archivolectura >> porcentajes[i][1];
- archivolectura >> porcentajes[i][2];
- archivolectura2 >> porcentajeslae[i][0];
- archivolectura2 >> porcentajeslae[i][1];
- archivolectura2 >> porcentajeslae[i][2];
- sumas[i][2]=porcentajes[i][2]+porcentajes[i][1]+porcentajes[i][0];
- sumas[i][1]=porcentajes[i][1]+porcentajes[i][0];
- sumas[i][0]=porcentajes[i][0];
- unos[i]=0;
- equis[i]=0;
- doses[i]=0;
- col1[i]=0;
- col2[i]=0;
- col3[i]=0;
- simulada[i]=0;
- }
- unos[14]=0;
- equis[14]=0;
- doses[14]=0;
- col1[14]=0;
- col2[14]=0;
- col3[14]=0;
- archivolectura.close();
- archivolectura2.close();
- archivolectura.open("base.txt");
- getline(archivolectura,col1s);
- getline(archivolectura,col2s);
- getline(archivolectura,col3s);
- // archivolectura>>liston;
- archivolectura>>recaudacion;
- archivolectura.close();
- cout << "Porcentajes leidos." << endl;
- cout << "Calculando..." << endl;
- simuladas=0;
- while(not fin){
- c1=0; cx=0; c2=0;
- ac1=0; ac2=0; ac3=0;
- probabilidad=1;
- probreal=1;
- for(int i=0; i<14; i++){
- if(simulada[i]==0){
- c1++;
- probabilidad*=porcentajeslae[i][0]/100;
- probreal*=porcentajes[i][0];
- if(col1s[i]=='1') ac1++;
- if(col2s[i]=='1') ac2++;
- if(col3s[i]=='1') ac3++;
- }else{
- if(simulada[i]==1){
- cx++;
- probabilidad*=porcentajeslae[i][1]/100;
- probreal*=porcentajes[i][1];
- if(col1s[i]=='x') ac1++;
- if(col2s[i]=='x') ac2++;
- if(col3s[i]=='x') ac3++;
- }else{
- c2++;
- probabilidad*=porcentajeslae[i][2]/100;
- probreal*=porcentajes[i][2];
- if(col1s[i]=='2') ac1++;
- if(col2s[i]=='2') ac2++;
- if(col3s[i]=='2') ac3++;
- }
- }
- }
- simuladas++;
- simulada[13]++;
- for(int i=13; i>0; i--){
- if(simulada[i]==3){
- simulada[i]=0;
- simulada[i-1]++;
- }
- }
- if(simulada[0]==3) fin=true;
- acertantes=(2*recaudacion)*probabilidad;
- if(acertantes==0) acertantes=1;
- premio=0.12*((double)recaudacion/acertantes);
- // if(premio<30000) continue;
- auxi=cx+c2;
- // if(auxi<5 or auxi>9) continue;
- // if(LAE) if(premio<liston) continue;
- // if(cx+c2<6 or cx+c2>10) continue;
- //liston
- // if(premio>liston){ caras++; probcaras+=probreal;}
- for(int i=0; i<listones; i++) if(premio>liston[i]) probcaras[i]+=probreal;
- premiomedio+=premio*probreal;
- probtotal+=probreal;
- unos[c1]+=probreal;
- equis[cx]+=probreal;
- doses[c2]+=probreal;
- col1[ac1]+=probreal;
- col2[ac2]+=probreal;
- col3[ac3]+=probreal;
- var[cx+c2]+=probreal;
- }
- cout << endl;
- cout << "N\t%1\t%X\t%2\t%VAR\tAc1\tAc2\tAc3"<<endl;
- for(int i=0; i<15; i++){
- setiosflags(ios::fixed);
- setprecision(3);
- cout << i <<"\t"<<setiosflags(ios::fixed)<<setprecision(3)<<(double)unos[i]/probtotal<<"\t"<<(double)equis[i]/probtotal<<"\t"<<(double)doses[i]/probtotal<<"\t"<<(double)var[i]/probtotal;
- cout <<"\t"<<(double)col1[i]/probtotal<<"\t"<<(double)col2[i]/probtotal<<"\t"<<(double)col3[i]/probtotal<<endl;
- }
- cout << endl;
- cout << "Simuladas " << simuladas << " columnas. Premio medio: "<<setprecision(0)<<(double)premiomedio/probtotal<<"."<<endl;
- cout << endl;
- cout << "Premio\tProb. de premio de 14 mayor" << endl;
- for(int i=0; i<listones; i++) cout << setprecision(0)<< liston[i]<< "\t" << setprecision(2)<< (double)100*probcaras[i]/probtotal << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement