Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.53 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.    
  4.     static int generuj(int xi) {
  5.         return ((xi * 25173) + 13849) % 65536;
  6.     }
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner input = new Scanner( System.in );
  10.         int N = input.nextInt();
  11.         int M = (int)Math.pow(2,N);
  12.         int MM = M;
  13.         int s0 = input.nextInt();
  14.         int[][] pole = new int[N+1][];
  15.         int[][] pole_hraci = new int[N+1][];
  16.         pole[0] = new int [M];
  17.         pole_hraci[0] = new int [M];
  18.         for (int i = 0; i < M; i++){                       
  19.             int s = generuj(s0);
  20.             s0 = s;
  21.             pole[0][i] = s;
  22.             pole_hraci[0][i] = i;
  23.         }
  24.         for (int j = 1; j <= N; j++) {
  25.             M = M / 2;
  26.             pole[j] = new int[M];
  27.             pole_hraci[j] = new int[M];
  28.             for (int k = 0, k2 = 0; k < M; k++, k2 = k2+2){
  29.                 if (pole[j-1][k2] >= pole[j-1][k2+1]) {
  30.                     pole[j][k] = pole[j-1][k2];
  31.                     pole_hraci[j][k] = pole_hraci[j-1][k2];
  32.                 }
  33.                 else {
  34.                     pole[j][k] = pole[j-1][k2+1];
  35.                     pole_hraci[j][k] = pole_hraci[j-1][k2+1];
  36.                 }
  37.             }          
  38.         }
  39.         System.out.println((pole_hraci[N][0]+1)+" "+pole[N][0]);
  40.                        
  41.         int pocet_zmien = input.nextInt();
  42.        
  43.         for (int i = 0; i < pocet_zmien; i++){
  44.             int zmena_kto = input.nextInt();
  45.             int zmena_skill = input.nextInt();
  46.             pole[0][zmena_kto-1] = pole[0][zmena_kto-1] + zmena_skill;
  47.             M = MM;
  48.             int pocet_vyhier = 0;
  49.             for (int j = 1; j <= N; j++) {
  50.                 int pom = pocet_vyhier;
  51.                 int k = zmena_kto-1;
  52.                 M = M / 2;
  53.                 if ((k % 2 )== 1) {
  54.                     if (pole[j-1][k] >= pole[j-1][k-1]){
  55.                         pole[j][((k-1) / 2)] = pole[j-1][k];
  56.                         pole_hraci[j][((k-1) / 2)] = pole_hraci[j-1][k];  
  57.                         pocet_vyhier++;
  58.                         k = ((k-1) / 2);
  59.                     }
  60.                     else {
  61.                         j = N+1;
  62.                     }                  
  63.                 }
  64.                 else {
  65.                     if (pole[j-1][k] >= pole[j-1][k+1]){
  66.                         pole[j][(k / 2)] = pole[j-1][k];
  67.                         pole_hraci[j][(k / 2)] = pole_hraci[j-1][k];
  68.                         pocet_vyhier++;
  69.                         k = ((k) / 2);
  70.                     }
  71.                     else {
  72.                         j = N+1;
  73.                     }              
  74.                 }
  75.                 if (pom == pocet_vyhier) j = N+1;
  76.             }          
  77.             System.out.println(pocet_vyhier);
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement