Skip to content

Commit

Permalink
sei la
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanCruz committed Jul 28, 2018
1 parent 6d062d9 commit 46051ff
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include<iostream>
#include<algorithm>

using namespace std;

int main(void){


return 0;
}
58 changes: 58 additions & 0 deletions codcad/programming-techniques/greedy/bolsas.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include<stdio.h>
#include<stdlib.h>

typedef struct bolsa bolsa;
struct bolsa{
int duracao;
int entrega;
};

int comp(const void * a, const void * b){
printf("%d %d\n", (*(bolsa*)a).entrega, ((*(bolsa*)b).entrega ));
return ((*(bolsa*)a).entrega < (*(bolsa*)b).entrega);
}

int max(int a, int b){
return a > b? a : b;
}

int atraso(bolsa b, int tempoAtual){
return max(0, tempoAtual + b.duracao - b.entrega);
}

int maiorAtraso(bolsa * bolsas, int qtdBolsas){
int tempoAtual = 0;
int maiorAtrasoTmp = 0;

for(int i = 0; i < qtdBolsas; i++){
maiorAtrasoTmp = max(atraso(bolsas[i], tempoAtual), maiorAtrasoTmp);
tempoAtual += bolsas[i].duracao;
}

return maiorAtrasoTmp;
}

int main(void){
// leitura dos dados
int qtdBolsas;
scanf("%d", &qtdBolsas);

bolsa bolsas[qtdBolsas];
for(int i = 0; i < qtdBolsas; i++){
scanf("%d %d", &(bolsas[i].duracao), &(bolsas[i].entrega));
}

for(int i = 0; i < qtdBolsas; i++){
printf("%d ", bolsas[i].entrega);
}
printf("\n");
qsort(bolsas, qtdBolsas, sizeof(bolsa), comp);
for(int i = 0; i < qtdBolsas; i++){
printf("%d ", bolsas[i].entrega);
}

printf("\n");
printf("%d\n", maiorAtraso(bolsas, qtdBolsas));

return 0;
}
51 changes: 51 additions & 0 deletions codcad/programming-techniques/greedy/bolsas.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include<iostream>
#include<algorithm>

using namespace std;

typedef struct bolsa bolsa;
struct bolsa{
int duracao;
int entrega;
};

int comp(bolsa a, bolsa b){
return a.entrega < b.entrega;
}

int max(int a, int b){
return a > b? a : b;
}

int atraso(bolsa b, int tempoAtual){
return max(0, tempoAtual + b.duracao - b.entrega);
}

int maiorAtraso(bolsa * bolsas, int qtdBolsas){
int tempoAtual = 0;
int maiorAtrasoTmp = 0;

for(int i = 0; i < qtdBolsas; i++){
maiorAtrasoTmp = max(atraso(bolsas[i], tempoAtual), maiorAtrasoTmp);
tempoAtual += bolsas[i].duracao;
}

return maiorAtrasoTmp;
}

int main(void){
// leitura dos dados
int qtdBolsas;
scanf("%d", &qtdBolsas);

bolsa bolsas[qtdBolsas];
for(int i = 0; i < qtdBolsas; i++){
scanf("%d %d", &(bolsas[i].duracao), &(bolsas[i].entrega));
}

sort(bolsas, bolsas + qtdBolsas, comp);

printf("%d\n", maiorAtraso(bolsas, qtdBolsas));

return 0;
}
4 changes: 4 additions & 0 deletions codcad/programming-techniques/greedy/inputBolsa1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2
1 100
10 10

4 changes: 4 additions & 0 deletions codcad/programming-techniques/greedy/inputBolsa2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2
1 2
10 10

9 changes: 9 additions & 0 deletions ime-2017/escala-musical/input1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
8
1
3
5
6
8
10
12
13
11 changes: 11 additions & 0 deletions ime-2017/escala-musical/input2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
10
8
11
21
16
11
8
27
57
27
21
8 changes: 8 additions & 0 deletions ime-2017/escala-musical/input3
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
7
2
2
4
3
12
12
3
149 changes: 149 additions & 0 deletions ime-2017/escala-musical/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#include<stdio.h>
#include<stdlib.h>

int comp(const void * a, const void * b){
return (*(int*)a > *(int*)b);
}

int printVetor(int * vetor, int n){
for(int i = 0; i < n; i++){
printf("%d ", vetor[i]);
}
printf("\n");
}

char * seqName(int value){
char * c;
switch(value){
case 0:
c = "do\0";
break;

case 1:
c = "do#\0";
break;

case 2:
c = "re\0";
break;

case 3:
c = "re#\0";
break;

case 4:
c = "mi\0";
break;

case 5:
c = "fa\0";
break;

case 6:
c = "fa#\0";
break;

case 7:
c = "sol\0";
break;

case 8:
c = "sol#\0";
break;

case 9:
c = "la\0";
break;

case 10:
c = "la#\0";
break;

default:
c = "si\0";
break;
}

return c;
}

int pattern[] = {2, 2, 1, 2, 2, 2, 1};
int patternSize = 7;
int qtdNotas = 12;

int * geradorDePatterns(int notaInicial) {
int * newPattern = (int*) malloc((patternSize+1)* sizeof(int));
newPattern[0] = notaInicial;

for(int i = 1; i <= patternSize; i++){
newPattern[i] = (newPattern[i-1] + pattern[i-1]) % qtdNotas;
}

return newPattern;
}

int diffNotas(int a, int b){
int diff = b - a;
diff = (diff < qtdNotas - diff) ? diff : qtdNotas - diff;

return diff;
}

int checkPattern(int * somePattern, int x){
printVetor(somePattern, patternSize);
int isPattern = 1;
for(int i = 0; i < 7 && isPattern; i++){
isPattern = somePattern[i] == pattern[(i+x) % patternSize];
}

return isPattern;
}

int main(void) {
for(int i = 0; i < 12; i++){
printVetor(geradorDePatterns(i), patternSize+1);
}
printf("----\n");

long n;
scanf("%ld", &n);

// le as notas
int notas[n];
for(long i = 0; i < n; i++){
int nota;
scanf("%d", &nota);
notas[i] = (nota-1) % 12;
}

// transforma em um vetor de notas individuais
qsort(notas, n, sizeof(int), comp);
int notasInd[12];
int iNotasInd = 0;
notasInd[iNotasInd++] = notas[0];
long i;
for(i = 1; i < n; i++){
while(notas[i] == notas[i-1] && i < n) i++;
if(i == n) break;

notasInd[iNotasInd++] = notas[i];
}

printVetor(notasInd, iNotasInd);

int isPattern = 0;



char * patternName;
if(!isPattern){
patternName = "desafinado\0";
}else{
patternName = seqName(notas[0] + i - 1);
}

printf("%s\n", patternName);
return 0;
}


35 changes: 35 additions & 0 deletions ime-2017/escala-musical/main2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include<stdlib.h>
#include<stdio.h>
int QTD_NOTAS = 12;

typedef struct noLigado * noLigado;
struct noLigado {
int valor;
noLigado prox;
};

void adicionaNo(noLigado * lista, noLigado no){
if(*lista == NULL){
*lista = no;
}else{
noLigado cabeca = *lista;
while(lista->prox != cabeca){

}
}
}

int main(void){
long n;
scanf("%ld", &n);

int tmp;
int notas[n];
for(long i = 0; i < n; i++){
scanf("%d", &tmp);
notas[i] = (tmp-1) % QTD_NOTAS;
}


return 0;
}

0 comments on commit 46051ff

Please sign in to comment.