Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) throws IOException {
- int ponto, melhorResposta, tamLado, i, j, k, minCortes;
- BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
- Scanner scan = new Scanner(System.in);
- boolean pos;
- int[] pontos = new int[10000000];
- int[] arcos = new int[10000];
- while (true) {
- int N = scan.nextInt();
- if (N == 0) {
- break;
- }
- String temp = bf.readLine();
- Scanner s = new Scanner(temp);
- int perimetroGeral = 0;
- i = 0;
- while (s.hasNext()) {
- arcos[i] = s.nextInt();
- perimetroGeral += arcos[i];
- i++;
- }
- for (i = 0; i < perimetroGeral; i++) {
- pontos[i] = 0;
- }
- ponto = 0;
- for (i = 0; i < N; i++) {
- pontos[ponto] = 1;
- ponto += arcos[i];
- }
- melhorResposta = -1;
- for (i = N; i >= 3; i--) {
- boolean acabou = false;
- if (perimetroGeral % i == 0) {
- tamLado = (perimetroGeral / i);
- for (j = 0; j < tamLado; j++) {
- pos = true;
- k = j;
- while (k < perimetroGeral) {
- if (pontos[k] == 0) {
- pos = false;
- break;
- }
- k += tamLado;
- }
- if (pos) {
- melhorResposta = i;
- acabou = true;
- break;
- }
- }
- }
- if (acabou) {
- break;
- }
- }
- minCortes = (melhorResposta == -1) ? -1 : N - melhorResposta;
- System.out.println(minCortes);
- }
- }
- }
Add Comment
Please, Sign In to add comment