miércoles, 21 de enero de 2015

Solucion uva 737

/*
 * 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.
 */

package uva737;
import java.util.Scanner;

/**
 *
 * @author Juan
 */
public class Uva737 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner leer = new Scanner(System.in);
        int vol,cubos,lado,x,y,z,inx,iny,
inz,finx,finy,finz;
       
           
         cubos=leer.nextInt();
         while (cubos>0){
             inx=leer.nextInt();
             iny=leer.nextInt();
             inz=leer.nextInt();
             lado=leer.nextInt();
             finx=inx+lado;
             finy=iny+lado;
             finz=inz+lado;
             for (int i = 1; i < cubos; i++) {
                 x=leer.nextInt();
                 y=leer.nextInt();
                 z=leer.nextInt();
                 lado=leer.nextInt();
                 inx=Math.max(inx, x);
                 iny=Math.max(iny, y);
                 inz=Math.max(inz, z);
                 finx=Math.min(finx, x+lado);
                 finy=Math.min(finy, y+lado);
                 finz=Math.min(finz, z+lado);
                
             }
             vol=Math.max(0, (finx-inx)*(finy-iny)*(finz-inz));
             System.out.println(vol);
            
             cubos = leer.nextInt();
         }
    }
}
http://solucionesuva.blogspot.com.es/2015/01/737-gleaming-cubes.html

No hay comentarios:

Publicar un comentario