Soh pra trabalho

4 respostas
T
package jazidaPack;

import jdsl.core.api.Sequence ;
import jdsl.core.ref.NodeSequence ;


public class Cel { 
	private Sequence s ; 
	private double teorC ;
	private boolean visited ;
	private int  cx,cy,cz;
	
		public Cel()
	{
		s = new NodeSequence() ;
		teorC = 0;	
		setVisited(false) ;
	}
	
	public void AddPonto(Ponto p){
		s.insertLast(p) ;
	}
	
	public double getTeor(){
		Ponto x = new Ponto() ;
		double teor = 0 ;
		for (int i = 0 ; i<s.size() ; i++){
			x = (Ponto)
			s.atRank(i).element() ;
			teor = teor + x.gettp() ;
		}
		if (s.size() == 0)
			teorC = 0 ;
		else
			teorC = teor/s.size() ;
		return teorC ;
	}
	
	public void setTeor(double T){
		teorC = T ;
	}
	
	public void setCords(int cx, int cy, int cz)
	{
		this.cx=cx;
		this.cy=cy;
		this.cz=cz;
	}
	
	public int getcx ()
	{
		return cx;
	}
	
	public int getcy ()
	{
		return cy;
	}
	
	public int getcz ()
	{
		return cz;
	}
	
	public void setVisited(boolean x){
		visited = x ;
	}
	
	public boolean getVisited(){
		return visited ;
	}
	
	public String toString(){
		return "\t "+cx+"\t "+cy+"\t "+cz+"\t Teor: " +teorC  ;
	}
		
}
package jazidaPack;

public class Ponto {
	private double px , py , pz , tp ;
	public Ponto(){
		px = 0 ;
		py = 0 ;
		pz = 0 ;
		tp = 0 ;
	}
	public Ponto(double x,double y,double z,double teor) {
		px = x ;
		py = y ;
		pz = z ;
		tp = teor ;
	}
	public double gettp(){
		return tp ;
	}
	public double getpx(){
		return px ;
	}
	public double getpy(){
		return py ;
	}
	public double getpz(){
		return pz ;
	}
	
	public String toString()
	{
		return String.format( "Ponto de coordenadas : "+ px + " " + py + " " + pz + "    e teor: " + tp );
	}
			}

4 Respostas

thundercas

Você está com alguma dúvida ou foi só para mostrar mesmo?

T

eh soh pra eu ter meu codigo enumerado mesmo agorinha vou apagar…

T
package jazidaPack;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import jdsl.core.api.Sequence;
import jdsl.core.ref.NodeSequence;

public class Jazida {
	
	private static void inicializarJazida(Cel mapa[][][], int ndiv) {	
		for (int i=0; i<ndiv; i++){ // O(n³) pois mapa[i][j][k] = new Cel() tem custo O(1) e é feita n*n*n vezes através da combinação de For.
			for (int j=0; j<ndiv; j++){
				for(int k=0; k<ndiv; k++){
					mapa[i][j][k] = new Cel() ;  
				}
			}
		}
	}
		
	public static void insereMapa(double x,double y, double z,double teor,double fx,double fy,double fz, double dx, double dy, double dz, int ndiv , Cel mapa[][][])
	{
		Ponto p = new Ponto(x,y,z,teor); 
			
		int nx = (int)(x/dx); 
		int ny = (int)(y/dy); 
		int nz = (int)(z/dz); 
		
				
		if ( x<=fx || y<=fy || z<=fz ){
		
		mapa[nx][ny][nz].AddPonto(p);
		mapa[nx][ny][nz].setCords(nx, ny, nz);
	
		}
	}
	
	public static void Listateor(Cel mapa[][][] , int ndiv)
	{
		Sequence List = new NodeSequence();
		Cel maior = new Cel();
		
		for (int i=0; i<mapa.length ; i++){ // O(n³) pois as operações do For mais interno são O(1) e ele é realizado n*n*n vezes.
			for (int j=0; j<mapa.length ; j++){
				for(int k=0; k<mapa.length; k++)
				{
					if (mapa[i][j][k].getTeor()>0)
						List.insertLast(mapa[i][j][k]); 
					if (mapa[i][j][k].getTeor()> maior.getTeor()) 
						maior = mapa[i][j][k] ;
				}
			}
		}
		System.out.println("");
		System.out.println("==================================================================================================");
		System.out.println("\n Lista de células com teor não-nulo é:");
		System.out.println("\n \t X \t Y \t Z");

		for(int i=0 ; i<List.size() ;i++){ //		O(n) pois System.out.println( Viz.atRank(i).element()) tem custo O(1) e é ezecutado n vezes.
			System.out.println( List.atRank(i).element()); 
		}
		System.out.println("");
		System.out.println("==================================================================================================");		
			
		System.out.println("\n A Célula de maior teor: \n \n \t X \t Y \t Z ");
		System.out.println(maior.toString());		
		System.out.println("");
		System.out.println("==================================================================================================");
		System.out.println("\n Células vizinhas à célula de maior teor de coordenadas:\n\t "+maior.getcx()+"\t "+maior.getcy()+"\t "+maior.getcz()+"\t Teor: "+maior.getTeor());
		System.out.println("\n Células vizinhas: \n__________________________________________________________________________________________________\n");	
	
	
	Sequence Viz = new NodeSequence() ;
	final double taxa = 0.80 ;
	double teorBusca = maior.getTeor()*taxa ;
	
	Vizinhos (maior.getcx(),maior.getcy(),maior.getcz(),mapa , teorBusca , ndiv , Viz );
	if( Viz.size() == 0){
		System.out.println(" Não há células vizinhas");
	}
	else
		{
		for(int i=0 ; i<List.size() ;i++){ // O(n) pois System.out.println( List.atRank(i).element()) tem custo O(1) e é ezecutado n vezes.
		System.out.println( Viz.atRank(i).element());
		}
	}
	
		System.out.println("\n__________________________________________________________________________________________________");	

	}
	
	public static void Vizinhos( int a, int b, int c , Cel mapa[][][] , double teorBusca , int ndiv , Sequence Viz ){
		// O(n³) pois o metódo executa operações O(1) para quase todas as célula e temos n³ células, então no pior caso teremos custo O(n³)
		
		if( a+1 < ndiv )
		{
			if (mapa[a+1][b][c].getTeor()>= teorBusca && mapa[a+1][b][c].getVisited() == false) 
			{
				Viz.insertLast(mapa[a+1][b][c]) ;
				mapa[a+1][b][c].setVisited( true ) ;
				Vizinhos(a+1,b,c, mapa , teorBusca , ndiv ,Viz ) ;
			}
			
		}
		
		if( a-1 >= 0 )
		{
			if (mapa[a-1][b][c].getTeor()>= teorBusca && mapa[a-1][b][c].getVisited()== false) 
			{
				Viz.insertLast(mapa[a-1][b][c]);
				mapa[a-1][b][c].setVisited(true); 
				Vizinhos(a-1,b,c, mapa , teorBusca , ndiv, Viz);
			}
		}
		
		
		if( b+1 < ndiv)
		{
			if (mapa[a][b+1][c].getTeor()>= teorBusca && mapa[a][b+1][c].getVisited()==false )
			{
				Viz.insertLast(mapa[a][b+1][c]);
				mapa[a][b+1][c].setVisited(true); 
				Vizinhos(a,b+1,c, mapa ,teorBusca , ndiv, Viz);
			}
		}
		
		if(b-1>= 0)
		{
			if (mapa[a][b-1][c].getTeor()>= teorBusca && b-1>= 0 && mapa[a][b-1][c].getVisited()==false ) 
			{
				Viz.insertLast(mapa[a][b-1][c]);
				mapa[a][b-1][c].setVisited(true);
				Vizinhos(a,b-1,c, mapa , teorBusca, ndiv ,Viz );
			}
		}
		
		if( c+1 < ndiv)
		{
			if (mapa[a][b][c+1].getTeor()>= teorBusca  && mapa[a][b][c+1].getVisited()==false )
			{
				Viz.insertLast(mapa[a][b][c+1]);
				mapa[a][b][c+1].setVisited(true);
				Vizinhos(a,b,c+1, mapa , teorBusca , ndiv, Viz );
			}
		}
	

		if( c-1 >= 0 )
		{
			if (mapa[a][b][c-1].getTeor()>= teorBusca && mapa[a][b][c-1].getVisited()==false )
			{
				Viz.insertLast(mapa[a][b][c-1]);
				mapa[a][b][c-1].setVisited(true);
				Vizinhos(a,b,c-1, mapa , teorBusca , ndiv, Viz);
			}
		}
	}
	
	
	
	public static void main(String args []) 
	{
		System.out.println("\n==================================================================================================\n");
		
		double x = 0 , y = 0 , z = 0 , teor = 0 , dx = 0 , dy = 0 , dz = 0; 
		int ndiv , nPontos ;
		Scanner teclado = new Scanner(System.in);
		
		System.out.println(" Digite a o comprimento da dimensão X.");
		double fx = teclado.nextDouble();
		System.out.println(" Digite a o comprimento da dimensão Y.");
		double fy = teclado.nextDouble(); 
		System.out.println(" Digite a o comprimento da dimensão Z.");
		double fz = teclado.nextDouble();
		System.out.println("\n==================================================================================================");
		
		Scanner reader;
		try {
			reader = new Scanner( new File( "C:/jazida.txt" ));
			nPontos = Integer.parseInt( reader.next() ) ; 	// lê número de pontos
	        ndiv = Integer.parseInt( reader.next() ) ; 		// lê número de divisoes
	       		
			dx = fx/ndiv ;
			dy = fy/ndiv ;
			dz = fz/ndiv ;
			
			
			Cel mapa[][][] = new Cel[ndiv][ndiv][ndiv]; 
			inicializarJazida( mapa , ndiv ) ;
			System.out.println("\n Lista de todos os pontos inseridos:\n \n \t   X \t\t  Y \t\t  Z");
			
			for (int i = 0 ; i <= nPontos-1 ; i++ ) // O(n) pois o For executa as ações dentro dele que tem custo O(1) n vezes.
			{
			  	
				x =	 Double.parseDouble( reader.next() ) ;	
		        y =  Double.parseDouble( reader.next() ) ;	
		        z =  Double.parseDouble( reader.next() ) ;	
		        teor = Double.parseDouble( reader.next() ) ;
		        
		        if ( x>fx || y>fy || z>fz )
		        System.out.println("\t"+x+"\t\t"+y+"\t\t"+z+"\t Teor: "+teor+"\t Este Ponto não pertende ao terreno");
		        else{
		        System.out.printf("\t %.2f \t\t%.2f \t\t%.2f \t Teor: %.2f \n" ,x ,y ,z ,teor);
		        insereMapa( x , y , z , teor ,fx,fy,fz, dx , dy , dz , ndiv , mapa );
		        }    
			}
			 Listateor(mapa , ndiv); //O(1)
		} 
		
		catch (FileNotFoundException e) {
			System.out.println("Arquivo não existente!");
			System.exit(0);
		}
 
		}
	}
rockstorm

Amigo,
o forum não serve para isto. Só faltava essa!!
Usar o forum para numerar as linhas do codigo…

Criado 7 de dezembro de 2007
Ultima resposta 7 de dez. de 2007
Respostas 4
Participantes 3