Guest User

Untitled

a guest
Apr 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Scanner;
  5. public class Main {
  6.     public static void main(String[] args) throws IOException {
  7.         int ponto, melhorResposta, tamLado, i, j, k, minCortes;
  8.         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  9.         Scanner scan = new Scanner(System.in);
  10.         boolean pos;
  11.         int[] pontos = new int[10000000];
  12.         int[] arcos = new int[10000];
  13.  
  14.  
  15.  
  16.         while (true) {
  17.             int N = scan.nextInt();
  18.             if (N == 0) {
  19.                 break;
  20.             }
  21.  
  22.             String temp = bf.readLine();
  23.             Scanner s = new Scanner(temp);
  24.             int perimetroGeral = 0;
  25.             i = 0;
  26.            
  27.             while (s.hasNext()) {
  28.                 arcos[i] = s.nextInt();
  29.                 perimetroGeral += arcos[i];
  30.                 i++;
  31.             }
  32.  
  33.             for (i = 0; i < perimetroGeral; i++) {
  34.                 pontos[i] = 0;
  35.             }
  36.             ponto = 0;
  37.             for (i = 0; i < N; i++) {
  38.                 pontos[ponto] = 1;
  39.                 ponto += arcos[i];
  40.             }
  41.  
  42.             melhorResposta = -1;
  43.  
  44.             for (i = N; i >= 3; i--) {
  45.                 boolean acabou = false;
  46.                 if (perimetroGeral % i == 0) {
  47.                     tamLado = (perimetroGeral / i);
  48.                     for (j = 0; j < tamLado; j++) {
  49.                         pos = true;
  50.                         k = j;
  51.  
  52.                         while (k < perimetroGeral) {
  53.                             if (pontos[k] == 0) {
  54.                                 pos = false;
  55.                                 break;
  56.                             }
  57.                             k += tamLado;
  58.                         }
  59.  
  60.                         if (pos) {
  61.                             melhorResposta = i;
  62.                             acabou = true;
  63.                             break;
  64.                         }
  65.                     }
  66.                 }
  67.                 if (acabou) {
  68.                     break;
  69.                 }
  70.             }
  71.  
  72.             minCortes = (melhorResposta == -1) ? -1 : N - melhorResposta;
  73.             System.out.println(minCortes);
  74.  
  75.         }
  76.     }
  77. }
Add Comment
Please, Sign In to add comment