Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. /*
  2. Simulador1X2 - Hector Ratia - Septiembre 2010
  3. */
  4. #include <iostream>
  5. #include <fstream>
  6. #include <string>
  7. #include <iomanip>
  8.  
  9. using namespace std;
  10.  
  11. double porcentajes[14][3];
  12. double sumas[14][3];
  13. double porcentajeslae[14][3];
  14.  
  15. int simulada[14];
  16.  
  17. int simuladas;
  18. double unos[15];
  19. double equis[15];
  20. double doses[15];
  21. double var[15];
  22.  
  23. double col1[15];
  24. double col2[15];
  25. double col3[15];
  26.  
  27. int c1;
  28. int cx;
  29. int c2;
  30.  
  31. int ac1;
  32. int ac2;
  33. int ac3;
  34.  
  35. int acertantes;
  36.  
  37. double probabilidad;
  38. double probreal;
  39. double probtotal=0;
  40. double premio;
  41. //double liston=30000;
  42. 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};
  43.  
  44. double premiomedio=0;
  45.  
  46. //bool LAE=false;
  47. int recaudacion=13000000;
  48.  
  49.  
  50. char c;
  51. double aux;
  52. string linea;
  53. bool fin=false;
  54. int auxi;
  55.  
  56. string col1s,col2s,col3s;
  57.  
  58. int main()
  59. {
  60. int listones=sizeof(liston)/sizeof(double);
  61. int caras[listones];
  62. double probcaras[listones];
  63.  
  64. ifstream archivolectura;
  65. ifstream archivolectura2;
  66.  
  67. archivolectura.open("bet.txt");
  68. archivolectura2.open("lae.txt");
  69.  
  70. for(int i=0; i<14; i++){
  71. archivolectura >> porcentajes[i][0];
  72. archivolectura >> porcentajes[i][1];
  73. archivolectura >> porcentajes[i][2];
  74. archivolectura2 >> porcentajeslae[i][0];
  75. archivolectura2 >> porcentajeslae[i][1];
  76. archivolectura2 >> porcentajeslae[i][2];
  77.  
  78. sumas[i][2]=porcentajes[i][2]+porcentajes[i][1]+porcentajes[i][0];
  79. sumas[i][1]=porcentajes[i][1]+porcentajes[i][0];
  80. sumas[i][0]=porcentajes[i][0];
  81. unos[i]=0;
  82. equis[i]=0;
  83. doses[i]=0;
  84. col1[i]=0;
  85. col2[i]=0;
  86. col3[i]=0;
  87.  
  88. simulada[i]=0;
  89. }
  90. unos[14]=0;
  91. equis[14]=0;
  92. doses[14]=0;
  93. col1[14]=0;
  94. col2[14]=0;
  95. col3[14]=0;
  96.  
  97. archivolectura.close();
  98. archivolectura2.close();
  99.  
  100. archivolectura.open("base.txt");
  101. getline(archivolectura,col1s);
  102. getline(archivolectura,col2s);
  103. getline(archivolectura,col3s);
  104. // archivolectura>>liston;
  105. archivolectura>>recaudacion;
  106. archivolectura.close();
  107.  
  108. cout << "Porcentajes leidos." << endl;
  109.  
  110. cout << "Calculando..." << endl;
  111.  
  112. simuladas=0;
  113.  
  114. while(not fin){
  115. c1=0; cx=0; c2=0;
  116. ac1=0; ac2=0; ac3=0;
  117. probabilidad=1;
  118. probreal=1;
  119. for(int i=0; i<14; i++){
  120. if(simulada[i]==0){
  121. c1++;
  122. probabilidad*=porcentajeslae[i][0]/100;
  123. probreal*=porcentajes[i][0];
  124. if(col1s[i]=='1') ac1++;
  125. if(col2s[i]=='1') ac2++;
  126. if(col3s[i]=='1') ac3++;
  127. }else{
  128. if(simulada[i]==1){
  129. cx++;
  130. probabilidad*=porcentajeslae[i][1]/100;
  131. probreal*=porcentajes[i][1];
  132. if(col1s[i]=='x') ac1++;
  133. if(col2s[i]=='x') ac2++;
  134. if(col3s[i]=='x') ac3++;
  135. }else{
  136. c2++;
  137. probabilidad*=porcentajeslae[i][2]/100;
  138. probreal*=porcentajes[i][2];
  139. if(col1s[i]=='2') ac1++;
  140. if(col2s[i]=='2') ac2++;
  141. if(col3s[i]=='2') ac3++;
  142. }
  143. }
  144. }
  145.  
  146. simuladas++;
  147.  
  148. simulada[13]++;
  149. for(int i=13; i>0; i--){
  150. if(simulada[i]==3){
  151. simulada[i]=0;
  152. simulada[i-1]++;
  153. }
  154. }
  155. if(simulada[0]==3) fin=true;
  156.  
  157. acertantes=(2*recaudacion)*probabilidad;
  158. if(acertantes==0) acertantes=1;
  159. premio=0.12*((double)recaudacion/acertantes);
  160.  
  161. // if(premio<30000) continue;
  162. auxi=cx+c2;
  163. // if(auxi<5 or auxi>9) continue;
  164. // if(LAE) if(premio<liston) continue;
  165. // if(cx+c2<6 or cx+c2>10) continue;
  166.  
  167. //liston
  168. // if(premio>liston){ caras++; probcaras+=probreal;}
  169. for(int i=0; i<listones; i++) if(premio>liston[i]) probcaras[i]+=probreal;
  170.  
  171. premiomedio+=premio*probreal;
  172. probtotal+=probreal;
  173. unos[c1]+=probreal;
  174. equis[cx]+=probreal;
  175. doses[c2]+=probreal;
  176. col1[ac1]+=probreal;
  177. col2[ac2]+=probreal;
  178. col3[ac3]+=probreal;
  179. var[cx+c2]+=probreal;
  180.  
  181. }
  182. cout << endl;
  183. cout << "N\t%1\t%X\t%2\t%VAR\tAc1\tAc2\tAc3"<<endl;
  184. for(int i=0; i<15; i++){
  185. setiosflags(ios::fixed);
  186. setprecision(3);
  187. 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;
  188. cout <<"\t"<<(double)col1[i]/probtotal<<"\t"<<(double)col2[i]/probtotal<<"\t"<<(double)col3[i]/probtotal<<endl;
  189. }
  190.  
  191. cout << endl;
  192. cout << "Simuladas " << simuladas << " columnas. Premio medio: "<<setprecision(0)<<(double)premiomedio/probtotal<<"."<<endl;
  193.  
  194. cout << endl;
  195. cout << "Premio\tProb. de premio de 14 mayor" << endl;
  196.  
  197. for(int i=0; i<listones; i++) cout << setprecision(0)<< liston[i]<< "\t" << setprecision(2)<< (double)100*probcaras[i]/probtotal << endl;
  198.  
  199.  
  200. return 0;
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement