terça-feira, 1 de agosto de 2017

Introdução à Análise de Algoritmos - planejamento e referências.


Na figura a bibliografia, tópicos principais e datas importantes.



O semestre é dividido em dois períodos. O primeiro período corresponde é o de aulas, o segundo período ao de recuperação. O calendário USP 2017 contém as datas de referência.

Segundo o Regimento Geral artigo 84 (consultado em 07.03.2017), Artigo 84 – Será aprovado, com direito aos créditos correspondentes, o aluno que obtiver nota final igual ou superior a cinco e tenha, no mínimo, setenta por cento de freqüência na disciplina.

No primeiro período haverá duas provas. O estudante que deixar de fazer uma delas pode fazer a prova substitutiva sem necessidade de justificativa adicional (critério estabelecido pelo docente).

P1: 15.09.2017
P2: 24.11.2017 adiantado para 21.11.2017 devido a prova de Cálculo

PSUB: 01.12.2017
PREC: 22.01.2018 (segunda-feira)

A média das provas é calculada: MP=0.4P1+0.6*P2

No primeiro período haverá 2 Exercícios-programa (EP). Tarefas realizadas em casa, entregues através do Tidia*

* Este é o Tidia 4, até o ano passado eu usava o Tidia 3.

             divulgação                 entrega                     tema
EP1           31.08                   02.10 (22h)              backtracking
EP2           08.11                   08.12 (22h)              hashing


A média dos EP é calculada MEP=(EP1+EP2)/2

A média no primeiro período é calculada: M1=0.8*MP+0.2*MEP

Tem nota para aprovação quem obtiver M1>=5.0 (obs.: 4,95<5.0)

No segundo período é realizada a avaliação de recuperação. Pode fazê-la quem tiver M1>=3.0

PREC: 22.01.2018 (segunda-feira)

A média no segundo período é calculada:

M2=(M1+PREC)/2

Tem nota para aprovação quem obtiver M2>=5.0 (obs.: 4,95<5.0)

A frequência mínima é de 70%, comprovada por assinatura em lista de presença. O abono de faltas é regulamentado por portaria da Comissão de Graduação.



quinta-feira, 25 de maio de 2017

Objeto No para implementar a Lista Ligada.

public class No {
 int valor;
 String payload;
 No prox;
 No (int valor, String payload) {
  this.valor=valor;
  this.payload=payload;
 }
}

Implemente a interface Busca usando busca binária.

public interface Busca {
 /**retorna o indice do elemento que contém o valor buscado.*/
 int busca (int valorBuscado);
}

Implemente a interface Dicionario usando uma lista ligada

public interface Dicionario {

 /** Insere como primeiro elemento da lista. */
 void insere (int valor, String payload);
 /** Remove o elemento que contém o valor buscado, retorna o payload. 
  * Não pode "quebrar" a lista. */
 String remove (int valorBuscado);
 /** Busca o valor, retorna o payload ou null caso não encontre. */
 String busca (int valorBuscado);
 /** Imprime os elementos da lista. */
 void print ();

}

quinta-feira, 4 de maio de 2017

código 2 aula de 04.05.2017 turma 3

import java.util.Random;

// one class needs to have a main() method
public class Penalti
{
  
  static int placarJogador = 0;
  static int placarGoleiro = 0;
  static int[][] gol = new int[3][5];

  static void imprimeGol() {
    System.out.println();
    for(int i=0; i < gol.length; i++) {
      for(int j=0; j < gol[import java.lang.Math; // headers MUST be above the first class
i].length; j++) {
        System.out.print(gol[i][j] + " ");
     }
      System.out.println();
    }
    
    System.out.println("PLACAR = JOGADOR " + placarJogador + " GOLEIRO " + placarGoleiro);
  }
 
  static void limpaGol() {
    for(int i=0; i < gol.length; i++) {
      for(int j=0; j < gol[i].length; j++) {
        gol[i][j] = 0;
     }
    }
  }
  
  
  static boolean defendeu(Jogador j, Goleiro g) {
    if(g.coluna == j.coluna) {
    System.out.println("DEFENDEU");
      placarGoleiro++;
      return true;
    }
    System.out.println("GOOOL");
    placarJogador++;
    return false;
  }
  

  public static void main(String[] args)
  {
   imprimeGol();
    Jogador rafinha = new Jogador();
    for (int i=0;i<5;i++) {
    //rafinha.chuta(0,0);
    rafinha.chuta();
    imprimeGol();
    Goleiro cassio = new Goleiro();
    //cassio.defende(0,0);
    cassio.defende();
    imprimeGol();
    defendeu(rafinha, cassio);
    imprimeGol();
    limpaGol();
    }    
  }
  
}

public class Jogador {
  
 // int[][] gol = Penalti.gol;
  int linha;
  int coluna;
  String nome;
  
  void chuta (int linha, int coluna) {
   this.linha = linha;
    this.coluna = coluna;
    Penalti.gol[linha][coluna] = 1;
          }
  void chuta () {
     Random r = new Random ();
      linha=r.nextInt (Penalti.gol.length);
      coluna=r.nextInt (Penalti.gol[0].length);
    Penalti.gol[linha][coluna] = 1;
  }
  
  public Jogador (){
    
  nome = "Hulk chuta";
  }
}

public class Goleiro {
int linha ;
 int coluna;
  
  void defende(int linha, int coluna) {
  this.linha = linha;
  this.coluna = coluna;
    Penalti.gol[linha][coluna] = 2;
  }
  void defende () {
     Random r = new Random ();
      linha=r.nextInt (Penalti.gol.length);
      coluna=r.nextInt (Penalti.gol[0].length);
      Penalti.gol[linha][coluna] = 2;
    for (int u = Penalti.gol.length-1 ; u >= 0; u--){
    Penalti.gol[u][coluna] = 2;
    
    }
  }

}

codigo 04.05.2017 - turma 3

//*******************************************************************
// Dear CompileJava users,
//
// CompileJava has been operating since 2013 completely free. If you
// find this site useful, or would otherwise like to contribute, then
// please consider a donation (link in 'More Info' tab) to support
// development of the new CompileJava website (stay tuned!).
//
// Most sincerely, Z.
//*******************************************************************

import java.lang.Math; // headers MUST be above the first class

// one class needs to have a main() method
public class HelloWorld
{
  // arguments are passed using the text field below this editor
  public static void main(String[] args)
  {
    OtherClass myObject = new OtherClass("Hello World!");
    System.out.print(myObject);
    /**/
    Classe c = new Classe();
    System.out.println (c.acesso()[2].toString());
    
  }
}

public class Classe {
   private OtherClass o = new OtherClass ("Classe");
  OtherClass[] acesso () {
    OtherClass[] array;
    array = new OtherClass[10];
    array[2]= new OtherClass ();
     return array;
  }
  
}

// you can add other public classes to this editor in any order
public class OtherClass
{
  private String message;
  private boolean answer = false;
  public OtherClass () {
    super();
  }
  public OtherClass(String input)
  {
    message = "Why, " + input + " Isn't this something?";
  }
  public String toString()
  {
    return message;
  }
}

codigo 04.05.2017 turma 2

//*******************************************************************
// Dear CompileJava users,
//
// CompileJava has been operating since 2013 completely free. If you
// find this site useful, or would otherwise like to contribute, then
// please consider a donation (link in 'More Info' tab) to support
// development of the new CompileJava website (stay tuned!).
//
// Most sincerely, Z.
//*******************************************************************

import java.lang.Math; // headers MUST be above the first class

// one class needs to have a main() method
public class HelloWorld
{
  // arguments are passed using the text field below this editor
  public static void main(String[] args)
  {
    OtherClass myObject = new OtherClass("Hello World!");
    System.out.print(myObject);
    System.out.println (myObject.message);
    
    Batata b = new Batata();
    System.out.println (b.retornaConteudo().message);
    System.out.println (b.retornaS());
    
    MeuObjeto meuObjeto = new MeuObjeto();
  }
}

class MeuObjeto {
  // atributos 
  // metodos
}


public class Batata {
    OtherClass o = new OtherClass ("Batata");
  OtherClass retornaConteudo () {
    return o;
  }
  String retornaS () {
    return o.toString();
  }

}
// you can add other public classes to this editor in any order
public class OtherClass
{
  public String message;
  private boolean answer = false;
  public OtherClass(String input)
  {
    message = "Why, " + input + " Isn't this something?";
    //return message;
  }
  public String toString()
  {
    return message;
  }
}