import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.math.*; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author jakab4 */ public class Most { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { // BufferedReader r = new BufferedReader(new FileReader(new File("C:\\Users\\jakab4\\Documents\\NetBeansProjects\\Most\\src\\vstup.txt"))); BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); int pocet = Integer.valueOf(r.readLine()); for(int i=0; i< pocet; i++) { int vstup = Integer.valueOf(r.readLine()); int [][] voda = new int[vstup][2]; StringTokenizer token; for(int j=0; j min){ } else{ if(voda[n][1]-voda[m][0] < 0) hodnota = Math.abs(m-n)-1; else hodnota = Math.abs(voda[m][0]-voda[n][1])+Math.abs(m-n); if(hodnota < min) min = hodnota; } } */ int x = 0; n =(m - min); if(n < 0) n = 0; while(true) { if(m==0) { if(x == voda.length) break; if(voda[x][1]-voda[0][0] < 0) hodnota = Math.abs(0-x)-1; else hodnota = Math.abs(voda[0][0]-voda[x][1])+Math.abs(0-x); if(hodnota < min) min = hodnota; x++; } else { if(n > (m +min) || n == voda.length) break; if(voda[n][1]-voda[m][0] < 0) hodnota = Math.abs(m-n)-1; else hodnota = Math.abs(voda[m][0]-voda[n][1])+Math.abs(m-n); if(hodnota < min) min = hodnota; n++; } } } System.out.println("K prechodu reky je treba " +(min) +" pontonu." ); } } }