-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
int main(){ | ||
int n,m, qt; | ||
char l; | ||
bool rodando; | ||
//cin >> n; | ||
while(cin>>n){ | ||
|
||
vector<int> tamanhos; | ||
vector<char> lados; | ||
rodando = true; | ||
|
||
for (int i = 0; i < n; i++) { | ||
cin >> m >> l; | ||
tamanhos.push_back(m); | ||
lados.push_back(l); | ||
} | ||
|
||
int q = 0; | ||
qt = 0; | ||
while(rodando){ | ||
for (int j = q+1; j < n; j++) { | ||
if(tamanhos.at(q)==tamanhos.at(j)){ | ||
if(lados.at(q)!=lados.at(j)){ | ||
qt++; | ||
tamanhos.erase(tamanhos.begin()+j); | ||
tamanhos.erase(tamanhos.begin()+q); | ||
lados.erase(lados.begin()+j); | ||
lados.erase(lados.begin()+q); | ||
q = 0; | ||
j = n; | ||
} | ||
} | ||
if(j == n-1){ | ||
q++; | ||
} | ||
} | ||
|
||
if((q == (tamanhos.size()-1))||(tamanhos.size()<=1)){ | ||
rodando = false; | ||
} | ||
} | ||
|
||
cout << qt << endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Desafios de Programação | ||
Repositorio para guardar codigos para treino de maratonas. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#include <iostream> | ||
#include <vector> | ||
using namespace std; | ||
|
||
int main(){ | ||
int n; | ||
cin >> n; | ||
|
||
if((n >= 1) && (n <= 100)){ | ||
int rel[n][n]; | ||
vector<int> h1; | ||
vector<int> h2; | ||
vector<int> restantes; | ||
|
||
//inserção dos dados | ||
for (int linha = 0; linha < n; linha++){ | ||
for (int coluna = 0; coluna < n; coluna++){ | ||
cin >> rel[linha][coluna]; | ||
} | ||
} | ||
|
||
//rel[aluno][relacoes] | ||
bool possivel = true; | ||
|
||
do{ | ||
//coloca os alunos em um vetor, para ajudar no controle e, caso um aluno não tenha amigos, | ||
//não precisaremos considerar ele no calculo de ser possivel ou nao | ||
for (int linha = 0; linha < n; linha++) { | ||
int i = 0; | ||
for (int coluna = 0; coluna < n; coluna++){ | ||
if (rel[linha][coluna] == 0){ | ||
i++; | ||
} | ||
} | ||
if(i < n){ | ||
restantes.push_back(linha); | ||
} | ||
} | ||
|
||
h1.push_back(restantes.at(0)); | ||
restantes.erase(restantes.begin()); | ||
|
||
int linha = 0; | ||
do{ | ||
|
||
//verifica o aluno com todos os que já estão no horario 1 | ||
int conth1 = 0; | ||
int conth2 = 0; | ||
int h1sizeaux = h1.size(); | ||
int h2sizeaux = h2.size(); | ||
for (int qt = 0; qt < h1sizeaux; qt++){ | ||
if (rel[restantes.at(linha)][h1.at(qt)] == 1){ | ||
if (h2.size() == 0){ //insere o primeiro item no 2° horario | ||
h2.push_back(restantes.at(linha)); | ||
restantes.erase(restantes.begin() + linha); | ||
linha = 0; | ||
qt = h1sizeaux; //para o loop, pois ja usamos o item da linha atual | ||
} | ||
else{ | ||
for (int qt2 = 0; qt2 < h2.size(); qt2++){ | ||
if (rel[restantes.at(linha)][h2.at(qt2)] == 1){ | ||
linha = (restantes.size() + 1); | ||
} | ||
else{ | ||
conth2++; | ||
} | ||
} | ||
if(conth2 == h2.size()){ | ||
h2.push_back(restantes.at(linha)); | ||
restantes.erase(restantes.begin() + linha); | ||
linha = 0; | ||
} | ||
else{ | ||
possivel = false; | ||
} | ||
} | ||
} | ||
else{ | ||
conth1++; | ||
} | ||
} | ||
//verifica condições para ser colocado no horario 1 | ||
if (conth1 == h1sizeaux){ | ||
int verVacuidade = 0; | ||
int conth2n = 0; | ||
for (int qt = 0; qt < h2sizeaux; qt++){ | ||
if(rel[restantes.at(linha)][qt] == 0){ | ||
conth2n++; | ||
} | ||
} | ||
//verifica se o aluno é amigo de pelo menos um do outro horario, | ||
if((conth2n != h2.size())||(h2.size() == 0)){ | ||
h1.push_back(restantes.at(linha)); | ||
restantes.erase(restantes.begin() + linha); | ||
linha = 0; | ||
}else{ | ||
linha++; | ||
if(linha >= restantes.size()){ //condição criada para evitar erros quando no vetor "restantes" sobraram somente itens | ||
h1.push_back(restantes.at(0)); //que interagem entre si, mas não com com os que ja estão nos vetores) | ||
restantes.erase(restantes.begin()); | ||
linha = 0; | ||
} | ||
} | ||
} | ||
}while((restantes.size() > 0)&&(possivel == true));/*&&(linha < restantes.size())*/ | ||
|
||
}while(1<0); | ||
if(restantes.size() == 0){ | ||
cout << "SIM"; | ||
} | ||
else{ | ||
cout << "NAO"; | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
typedef struct aluno aluno; | ||
struct aluno{ | ||
bool state; | ||
char direction; | ||
int number; | ||
} | ||
|
||
void virar(char * d){ | ||
if(*d == 'U'){ | ||
*d = 'R'; | ||
}else if(*d == 'R'){ | ||
*d = 'D'; | ||
}else if(*d == 'D'){ | ||
*d = 'L'; | ||
}else{ | ||
*d = 'U'; | ||
} | ||
} | ||
|
||
|
||
void executarInstrucoes(){ | ||
//virar(&c); | ||
} | ||
|
||
int main(){ | ||
int n; | ||
cin >> n; | ||
|
||
|
||
int i, j; | ||
cin >> a; | ||
cin >> b; | ||
|
||
aluno m[n][n]; | ||
|
||
for(int i = 0; i < n; i++){ | ||
for(int j = 0; j < n; j++){ | ||
cin >> aluno[m][n].shirt; | ||
aluno[i][j].state = 0; | ||
aluno[i][j].direction = 'U'; | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main(){ | ||
cout << "Ola CodCad!\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include <iostream> | ||
using namespace std; | ||
int main() { | ||
|
||
int n, k; | ||
|
||
cin >> n >> k; | ||
|
||
bool verif = true; | ||
int colunas[k]; | ||
int peso[n]; | ||
int qtItensCol[k]; | ||
int sequencia[n]; | ||
int somaCol; | ||
int qtItensAux; | ||
|
||
//inserção dos pesos | ||
for (int i = 0; i<n; i++){ | ||
cin >> peso[i]; | ||
} | ||
|
||
for (int i = 0; i<k; i++){ | ||
qtItensCol[i] = 0; | ||
} | ||
|
||
|
||
for(int nfor = 0; nfor < n; nfor++){ //passar por cada item | ||
for (int col = 0; col < k; col++){ //passar por cada coluna | ||
|
||
//caso não tenha itens na coluna | ||
if(qtItensCol[col] == 0){ | ||
sequencia[nfor] = col; | ||
col = k; //para finalizar o for | ||
qtItensCol[col]++; | ||
} | ||
|
||
else{ | ||
qtItensAux = qtItensCol[col]; | ||
int pesosAux[(qtItensCol[col])]; | ||
|
||
//atribuição dos valores ao vetor pesosAux[] | ||
for(int z = (nfor-1); z >= 0; z--){ | ||
if(sequencia[z] == col){ | ||
qtItensAux--; | ||
pesosAux[qtItensAux] = peso[z]; | ||
} | ||
} | ||
|
||
//comparação do peso atual com os alocados | ||
//qt de verificações | ||
|
||
somaCol = peso[nfor]; | ||
|
||
int i2 = (qtItensCol[col] - 1); | ||
|
||
do{ | ||
if(somaCol <= pesosAux[i2]){ | ||
if (i2 == 0){ | ||
sequencia[nfor] = col; | ||
col = k; | ||
qtItensCol[col]++; | ||
} | ||
|
||
else{ | ||
somaCol = somaCol + pesosAux[i2]; | ||
|
||
} | ||
i2--; | ||
} | ||
else{ | ||
//caso o número de colunas disponiveis acabe | ||
if(col == (k-1)){ | ||
verif = false; | ||
nfor = n; | ||
} | ||
i2 = -1; | ||
} | ||
|
||
}while(i2 >= 0); | ||
} | ||
} | ||
} | ||
|
||
if(verif == true){ | ||
for(int d = 0; d < n; d++){ | ||
cout << sequencia[d]; | ||
} | ||
} | ||
else{ | ||
cout << "IMP"; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.