Advertisement
Guest User

Winter_cup_dota2

a guest
Oct 8th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.39 KB | None | 0 0
  1. import java.text.DecimalFormat;
  2.  
  3. public class torneo {
  4.     private static int M=8;     // Número de equipos
  5.     private static int N=7;     // Número de jugadores por equipo
  6.     private static int L=56;    // Número de jugadores del torneo
  7.     private static double E = 6.7;  // Valor mínimo para considerar una solución como éxito
  8.     private double valorMejor=9999;     // La mejor diferencia entre el equipo con más puntos y el que tenga menos.
  9.     private int solMejor[]=new int[L];  // La mejor solución
  10.     private boolean exito = false;      // Nos dice si ha encontrado una solución optima
  11.     private String equipos[]={"Lannisters","Tullys","Baratheons","Tyrells","Martells","Targaryens","Greyjoys","Starks"};
  12.    
  13.     private class jugador{
  14.         private int n;
  15.         private String nick_mv;
  16.         private String nick_steam;
  17.         private String steamid;
  18.         private int rol1;
  19.         private int rol2;
  20.         private String post;
  21.         private double kad;
  22.         private int jugadas;
  23.         private int ganadas;
  24.         private int perdidas;
  25.         private int lastHits;
  26.         private int denies;
  27.        
  28.         public jugador(int n, String n1, String n2, String s, int r1, int r2, String p, double kad, int nj, int ng, int np, int lh, int de){
  29.             this.n = n;
  30.             this.nick_mv = n1;
  31.             this.nick_steam = n2;
  32.             this.steamid = s;
  33.             this.rol1 = r1;
  34.             this.rol2 = r2;
  35.             this.post = p;
  36.             this.kad = kad;
  37.             this.jugadas = nj;
  38.             this.ganadas = ng;
  39.             this.perdidas= np;
  40.             this.lastHits= lh;
  41.             this.denies  = de;
  42.         }
  43.     }
  44.    
  45.     private jugador datos[]={
  46.         new jugador(0,"Thanat0s","A700727","STEAM_0:0:13128",2,3,"#1",3.31,967,482,485,104330,7031),
  47.         new jugador(1,"Birras_cs","d~","STEAM_0:1:8040576",3,2,"#2",2.34,794,391,403,120166,5810),
  48.         new jugador(2,"Foxtreme","Foxt","STEAM_0:1:4157124",3,1,"#5",2.48,1219,643,576,138417,9681),
  49.         new jugador(3,"Zheiwander","nM. Zheiwander","STEAM_0:0:3411411",3,2,"#6",3.96,729,383,346,90624,7237),
  50.         //new jugador(4,"Chefaso","C","STEAM_0:0:14050369",2,3,"#7",4.03,1010,527,483,127572,5458),
  51.         new jugador(5,"Mamba","Mamba","STEAM_0:1:33889831",2,3,"#8",2.47,200,99,101,20854,1616),
  52.         new jugador(6,"HectorxD","HmgxD","STEAM_0:0:29950735",1,3,"#9",2.2,602,309,293,73072,3054),
  53.         new jugador(7,"SamaWoodo","SamaWoodo","STEAM_0:0:26123018",3,2,"#10",2.92,473,232,241,42331,3162),
  54.         new jugador(8,"Pato-WC","Fulgencio","STEAM_0:0:32324506",2,3,"#11",2.28,203,99,104,16590,873),
  55.         new jugador(9,"Fwend","Mr.Pinkman","STEAM_0:1:16204708",2,1,"#12",2.3,139,68,71,10967,879),
  56.         new jugador(10,"yuise","Sanguinius","STEAM_0:0:42567",2,3,"#13",2.55,409,206,203,31297,987),
  57.         new jugador(11,"Lutx1","lUtXo¹","STEAM_0:1:14743378",2,1,"#15",2.88,529,285,244,68149,4060),
  58.         new jugador(12,"GamanKi","NanD","STEAM_0:1:43365048",3,2,"#16",2.38,997,503,494,91159,5262),
  59.         new jugador(13,"plantaNieves","plantaNieves","STEAM_0:0:46330765",2,3,"#17",2.34,1156,577,579,110752,5863),
  60.         new jugador(14,"hoop","Kang Ji Young","STEAM_0:0:11522321",3,2,"#18",2.62,458,230,228,41957,3324),
  61.         new jugador(15,"Dota--do","Nick raro","STEAM_0:1:14013490",1,3,"#19",2.66,417,203,214,50848,2570),
  62.         new jugador(16,"UlfiNiste","UlfiNiste","STEAM_0:0:37712180",3,1,"#20",2.23,839,436,403,79440,5528),
  63.         new jugador(17,"Qwantz","nM . Qawaii","STEAM_0:1:10422573",3,1,"#21",2.67,778,400,378,88787,5745),
  64.         new jugador(18,"88Jack88","Suicide","STEAM_0:0:18434833",2,3,"#22",2.17,597,283,314,54012,2648),
  65.         new jugador(19,"Genesis1910","Genesis1910","STEAM_0:0:34616185",3,2,"#23",2.17,291,133,158,17505,1801),
  66.         new jugador(20,"Nilxd","Omdnil","STEAM_0:0:25408633",1,3,"#24",2.94,210,112,98,29896,1603),
  67.         new jugador(21,"dan1kkk","w00kiez","STEAM_0:0:7998597",2,3,"#25",3.02,1311,669,642,144964,3775),
  68.         new jugador(22,"Fr0z33n","Fr0z3n","STEAM_0:0:23978311",1,3,"#26",2.64,739,366,373,74007,2432),
  69.         new jugador(23,"maidu","maidu","STEAM_0:0:55330707",3,2,"#27",3.27,157,85,72,21691,1581),
  70.         new jugador(24,"LoLQoP","LoLQoP","STEAM_0:1:31735792",3,1,"#28",2.95,1649,910,739,228794,17199),
  71.         new jugador(25,"Sprana","EriiiC-","STEAM_0:0:43370512",1,3,"#29",2.7,1594,868,726,190466,15113),
  72.         new jugador(26,"Yerboth","Kung-Fumeta Style","STEAM_0:1:23973312",2,3,"#30",2.61,195,92,103,12936,1146),
  73.         new jugador(27,"MaSqUi","MaSqUi","STEAM_0:1:53871",2,3,"#31",2.2,77,40,37,4894,168),
  74.         new jugador(28,"Ragabash","ASES Ragabash","STEAM_0:0:43440307",3,1,"#32",2.99,759,384,375,94238,4552),
  75.         //new jugador(29,"cyber","cyber","STEAM_0:0:21479832",2,1,"#33",2.76,465,237,228,45642,2398),
  76.         new jugador(30,"narko1","nark0","STEAM_0:1:6176227",1,3,"#34",3.04,853,430,423,97142,3868),
  77.         new jugador(31,"Shakespeare","Shakespeare // Shk","STEAM_0:0:9012",2,3,"#35",2.37,918,484,434,80501,5240),
  78.         new jugador(32,"DaRk-eXe","Juancho","STEAM_0:1:2071482",1,3,"#36",3.26,860,417,443,113821,3992),
  79.         new jugador(33,"Ulmo","Menistar","STEAM_0:1:1454869",2,3,"#37",3.04,955,505,450,111107,5785),
  80.         new jugador(34,"Wuok4","AntenaDota.c0li","STEAM_0:1:15789281",2,3,"#38",2.76,838,430,408,73324,4563),
  81.         new jugador(35,"KaNeaS","KaNeaS","STEAM_0:1:14262",2,3,"#39",3.5,295,147,148,37719,1926),
  82.         new jugador(36,"Zhisky","San Bucardo Castor","STEAM_0:1:36203513",3,1,"#40",3.38,848,411,437,108263,5149),
  83.         new jugador(37,"F1lter","ASES filter!","STEAM_0:1:6771943",2,3,"#41",2.22,1102,554,548,104651,5851),
  84.         new jugador(38,"DeNz1L","denx","STEAM_0:0:8669749",1,3,"#45",2.43,453,246,207,53304,3419),
  85.         new jugador(39,"k1ng88","k1ng88","STEAM_0:1:9049025",3,1,"#46",2.67,715,369,346,77347,3397),
  86.         new jugador(40,"tmeto","tmeto","STEAM_0:0:48407610",1,3,"#47",2.02,171,84,87,13922,26),
  87.         new jugador(41,"Raku","Raku_risi","STEAM_0:0:15534982",2,1,"#55",2.42,558,282,276,58401,2711),
  88.         new jugador(42,"Fntk-","Fntk-","STEAM_0:0:43520932",2,1,"#65",2.66,625,307,318,73281,4704),
  89.         new jugador(43,"kaseiyo","Dr Lodrok","STEAM_0:0:26704571",3,2,"#68",2.5,742,364,378,85025,2100),
  90.         new jugador(44,"xPipOx","PipOisOk","STEAM_0:1:605469",1,2,"#71",4.77,119,60,59,12606,1106),
  91.         new jugador(45,"JksS","aBsONEEE","STEAM_0:0:4302609",2,3,"#72",2.84,86,49,37,6249,414),
  92.         new jugador(46,"jeisonxxx","jeisonxxx","STEAM_0:1:24911606",3,1,"#73",3.39,943,459,484,118691,5718),
  93.         new jugador(47,"Mikailovich","SrLobo","STEAM_0:1:4214047",2,3,"#74",2.45,552,287,265,44259,1950),
  94.         new jugador(48,"RoTTriK","[CD]Aguarras","STEAM_0:0:35111877",3,2,"#75",2.47,271,131,140,29624,1014),
  95.         new jugador(49,"Juxux_Fomare","Juxux","STEAM_0:0:16671117",2,3,"#76",2.72,463,247,216,53554,1234),
  96.         new jugador(50,"Obi","Obi","STEAM_0:0:15679804",2,1,"#78",1.78,191,89,102,12071,272),
  97.         new jugador(51,"Wildkah","Wildkah","STEAM_0:1:45675911",1,3,"#79",2.38,105,55,50,8906,499),
  98.         new jugador(52,"GeeKPoWa","GeeKPoWa!!1!one1!","STEAM_0:0:19302389",3,1,"#80",2.76,750,383,367,87492,3345),
  99.         new jugador(53,"CLON-Shark","shark4jnkkk","STEAM_0:1:14532707",1,2,"#83",3.53,817,427,390,92107,8059),
  100.         new jugador(54,"Cyronix","Cyronix","STEAM_0:1:46774930",2,1,"#96",2.51,219,113,106,23824,767),
  101.         new jugador(55,"4ngelote","4ngelote","STEAM_0:0:23826323",2,1,"#97",2.28,790,415,375,93464,5234),
  102.         new jugador(56,"vanaraug","Vanaraug","STEAM_0:1:29078708",1,2,"#84",3.44,191,94,97,19262,567),
  103.         new jugador(57,"jopas","yeskoN","STEAM_0:1:1221672",2,3,"#85",2.71,90,46,44,8433,452),
  104.         new jugador(58,"psicologo","aShock.psymx","STEAM_0:1:10927743",3,2,"#87",3.17,1020,522,498,95928,5126),
  105.         new jugador(59,"ONCE-Xxole","ONCE_Xxole","STEAM_0:0:45139081",3,2,"#88",2.59,812,417,395,76696,5437),
  106.         new jugador(60,"YuR1-","YuR1","STEAM_0:1:11881252",1,3,"#89",2.92,1855,1009,846,295393,10502),
  107.         new jugador(61,"Itoh","Itoh","STEAM_0:1:14079099",2,3,"#90",2.54,468,229,239,38949,1122),
  108.         new jugador(62,"SaRk1t0rZ","saRk","STEAM_0:1:10295233",2,3,"#91",2.39,389,201,188,47509,3096),
  109.         new jugador(63,"aldebaran00","ASES aldebaran-","STEAM_0:0:42922383",2,3,"#92",2.69,1146,620,526,119753,7777),
  110.         new jugador(64,"kNG17","BAASS","STEAM_0:1:24561659",3,2,"#93",2.74,476,224,252,31469,1547),
  111.         new jugador(65,"Horcus","Horcus","STEAM_0:0:33703302",1,3,"#94",3.05,750,391,359,91266,9114)
  112.     }; 
  113.    
  114.     private torneo(){
  115.         int sol[]=new int[L];
  116.         int cuantos[]=new int[M];
  117.         double suma[]=new double[M];
  118.         double puntos[]= calcularPuntos(this.datos);
  119.         calcularEquipos(sol,cuantos,suma,puntos,0);
  120.         System.out.println("*** Equipos finales ***");
  121.         System.out.println("--- Lista de jugadores ---");
  122.         suma = new double[M];
  123.         DecimalFormat df = new DecimalFormat("###.########");
  124.         for(int i=0; i<L; i++){
  125.             System.out.println(datos[i].nick_mv + " | " + datos[i].steamid + " | " + datos[i].post + " | " + equipos[solMejor[i]] + " | " + df.format(puntos[i]));
  126.             suma[solMejor[i]] = suma[solMejor[i]] + puntos[i];
  127.         }
  128.         System.out.println("--- Reservas ---");
  129.         for(int i=L; i<datos.length; i++){
  130.             System.out.println(datos[i].nick_mv + " | " + datos[i].steamid + " | " + datos[i].post + " | " + df.format(puntos[i]));
  131.         }
  132.        
  133.         System.out.println("--- Orden por Equipos ---");
  134.         for(int i=0; i<M; i++){
  135.             System.out.println("--- "+ equipos[i]+" ---");
  136.             for(int j=0; j<L; j++){
  137.                 if(solMejor[j]==i)
  138.                     System.out.println(datos[j].nick_mv + " | " + datos[j].steamid + " | " + datos[j].post + " | " + df.format(puntos[j]));
  139.             }
  140.         }
  141.         for(int i=0; i<M; i++)
  142.             System.out.println("Equipo "+equipos[i]+": "+df.format(suma[i]));
  143.     }
  144.    
  145.     private double[] calcularPuntos(jugador datos[]){
  146.         double aux[]=new double[datos.length];
  147.         double minimo = 9999;
  148.         for(int i=0; i<datos.length; i++){
  149.             aux[i] = datos[i].kad + ((datos[i].lastHits/datos[i].jugadas)-100)*0.1 + ((datos[i].denies/datos[i].jugadas)-5)*0.1 + (datos[i].ganadas-datos[i].perdidas)*0.1;
  150.             if(aux[i]<minimo) minimo = aux[i];
  151.         }
  152.         // Para evitar valores negativos sumamos a cada jugador el valor del jugador con menos puntos
  153.         for(int i=0; i<datos.length; i++)
  154.             aux[i] = aux[i] + -(minimo);
  155.         return aux.clone();
  156.     }
  157.    
  158.     private void calcularEquipos(int sol[], int cuantos[], double suma[], double puntos[], int k){
  159.         for(int i=0; i<M; i++){
  160.             if(!exito && cuantos[i]<N){
  161.                 sol[k]=i;
  162.                 cuantos[i]++;
  163.                 suma[i]=suma[i]+puntos[k];             
  164.                 if(k==L-1){
  165.                     double diferencia = sacarDiferencia(suma);
  166.                     if(diferencia<valorMejor){
  167.                         System.out.println("Ha llegado a una solución mejor: "+diferencia);
  168.                         solMejor=sol.clone();
  169.                         valorMejor=diferencia;
  170.                         // Si la diferencia es menor que un valor establecido, salimos
  171.                         if(diferencia<E) exito=true;
  172.                     }
  173.                 }
  174.                 else{
  175.                     // Podamos el árbol para intentar bajar el tiempo
  176.                     if(continuar(suma.clone(),i,puntos,cuantos,valorMejor,k+1))
  177.                         calcularEquipos(sol.clone(),cuantos.clone(),suma.clone(),puntos.clone(),k+1);
  178.                 }
  179.                 cuantos[i]--;
  180.                 suma[i]=suma[i]-puntos[k];
  181.             }
  182.         }
  183.     }
  184.    
  185.     private boolean continuar(double suma[], int j, double puntos[], int cuantos[], double dif_ant, int k){
  186.         // Sacamos la media de los jugadores
  187.         double sumaJug = 0;
  188.         for(int i=k; i<L; i++)
  189.             sumaJug = sumaJug + puntos[i];
  190.         double media = sumaJug / (L-k);
  191.         // Sumamos a los equipos con equipos que faltan la media de los jugadores
  192.         for(int i=0; i<M; i++)
  193.             if(cuantos[i]<N)
  194.                 suma[i]=suma[i]+(media*(N-cuantos[i]));
  195.         // Sacamos la nueva diferencia
  196.         double dif_act = sacarDiferencia(suma.clone());
  197.         if(dif_act<dif_ant)
  198.             return true;
  199.         else
  200.             return false;
  201.     }
  202.    
  203.     private double sacarDiferencia(double suma[]){
  204.         double minimo=9999;
  205.         double maximo=-9999;
  206.         for(int i=0; i<M; i++){
  207.             if(suma[i]<minimo)
  208.                 minimo=suma[i];
  209.             if(suma[i]>maximo)
  210.                 maximo=suma[i];
  211.         }
  212.         return maximo-minimo;
  213.     }
  214.    
  215.     public static void main(String[] args) {
  216.         new torneo();
  217.     }
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement