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