Skip to content

Instantly share code, notes, and snippets.

@gusanthiago
Created April 24, 2017 02:54
Show Gist options
  • Save gusanthiago/898f436849d0d6104fa97d5d68d6d405 to your computer and use it in GitHub Desktop.
Save gusanthiago/898f436849d0d6104fa97d5d68d6d405 to your computer and use it in GitHub Desktop.
maratonaInterna2015fatecsjc-algunsexers
#include <bits/stdc++.h>
using namespace std;
typedef struct {
double nota;
int falta;
string nome;
}aluno;
bool sortAluno(aluno a, aluno b) {
if (b.nota != a.nota)
return a.nota > b.nota;
if (b.falta != a.falta)
return a.falta < b.falta;
return a.nome < b.nome;
}
int main() {
int n;
string nome;
double nota=1;int falta=1;
vector<aluno> alunos;
aluno teste;
cin >> n;
for(int i=0;i<n;i++) {
cin >> nome >> nota >> falta;
teste.nome.assign(nome);
teste.nota = nota;
teste.falta = falta;
alunos.push_back(teste);
}
sort(alunos.begin(),alunos.end(),sortAluno);
cout << alunos[0].nome << endl;
for (int i=1;i<alunos.size();i++) {
if (alunos[i].falta == alunos[0].falta && alunos[i].nota == alunos[0].nota)
cout << alunos[i].nome << endl;
else
break;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main () {
int flag = 1, n, resp;
vector<int> elementos;
while (scanf("%d %d", &n, &resp) != EOF) {
flag = 0;
int num;
for (int i=0;i<n;i++) {
cin >> num;
elementos.push_back(num);
}
// https://en.wikipedia.org/wiki/3SUM
sort(elementos.begin(),elementos.end());
if (elementos[0] + elementos[1] + elementos[2] == 0) {
flag = 1;
} else {
n = elementos.size() - 2;
for (int i=0;i<n;i++) {
int a = elementos[i],
start = i+1,
end = elementos.size()-1;
while (start < end ) {
int b = elementos[start],
c = elementos[end];
if (a+b+c == 0) {
// printf ("chegou");
flag = 1;
end -= 1;
} else if (a + b + c > 0) {
end -= 1;
} else {
start += 1;
}
}
}
}
if (resp == flag) {
printf ("Y\n");
} else {
printf ("N\n");
}
elementos.clear();
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main() {
double vUcoder,vVaca,dParque,dVaca;
while(scanf("%lf %lf %lf %lf", &vVaca, &vUcoder, &dVaca, &dParque) != EOF) {
dVaca += dParque;
if ( dVaca / vVaca <= dParque / vUcoder) {
printf("x(\n");
} else {
printf(":)\n");
}
}
//
// sorvete
// s = v . t
//
// velocidade media - v (m)
// v = s
// t
//
//
// tempo q leva para ucoderBoy || vaca chegar no parque
// t = v(m)
// s
//
//
return 0;
}
#include <bits/stdc++.h>
using namespace std;
vector<int> valores,pesos;
int pd[32][64];
int mochila (int index, int peso) {
if (index < 0) return 0;
if (index == 0) {
if(pesos[index] <= peso)
return valores[index];
else
return 0;
}
if (pd[index][peso] != 0) return pd[index][peso];
int comElemento = 0, semElemento = 0;
if (pesos[index] <= peso) {
comElemento = valores[index] + mochila(index - 1, peso - pesos[index]);
}
semElemento = mochila(index - 1, peso);
return max (comElemento,semElemento);
}
int main() {
int n;
cin >> n;
memset(pd, 0, sizeof(pd));
while (n!=0) {
for(int i=0;i<n;i++) {
int livros,tempo;
cin >> livros >> tempo;
valores.push_back(livros);
pesos.push_back(tempo);
}
cout << mochila(pesos.size() - 1, 48) << " livro(s)" << endl;
valores.clear();
memset(pd, 0, sizeof(pd));
pesos.clear();
cin >> n;
}
return 0;
}
// nota casos de testes aparentam estar certos mais a saída do ucoder esta com IDs repetidos
#include <bits/stdc++.h>
using namespace std;
typedef struct {
int matou, morreu, numero;
}aluno;
vector <aluno> geralVet;
char definePonto(int a, int b){
if (a % 2 != 0)
return 't';
return 'c';
}
bool sortAluno(aluno a, aluno b){
if (a.matou != b.matou)
return a.matou > b.matou;
if (a.morreu != b.morreu)
return a.morreu < b.morreu;
return a.numero < b.numero;
}
void imprimeResult(map<int, aluno> a) {
geralVet.clear();
for (map<int, aluno>::iterator it=a.begin(); it!=a.end();it++)
geralVet.push_back(it->second);
sort(geralVet.begin(), geralVet.end(), sortAluno);
for (int i=0; i<geralVet.size(); i++)
cout << geralVet[i].numero << " " << geralVet[i].matou << " " << geralVet[i].morreu << endl;
}
int main() {
int n,contador = 1;
int a,b;
map <int, aluno > geral;
aluno temp;
int pontCT, pontT, morteCT, morteT;
while(cin >> n){
if (n == 0) break;
pontCT = 0, pontT = 0, morteCT = 0, morteT = 0;
while(n--) {
cin >> a >> b;
if (definePonto(a, b) == 'c') {
pontCT++;
morteT++;
} else {
pontT++;
morteCT++;
}
if (geral[a].numero == NULL) {
geral[a].numero = a;
geral[a].morreu = 0;
geral[a].matou = 1;
} else {
geral[a].matou += 1;
}
if (geral[b].numero == NULL) {
geral[b].numero = b;
geral[b].morreu = 1;
geral[b].matou = 0;
} else {
geral[b].morreu += 1;
}
}
cout << "Rodada " << contador<< ":" << endl;
if (pontT > pontCT) {
cout << "Grupo Vencedor T" << endl;
} else if (pontCT > pontT) {
cout << "Grupo Vencedor CT" << endl;
} else {
// não valida o empate
if (morteT < morteCT) {
cout << "Grupo Vencedor T" << endl;
} else {
cout << "Grupo Vencedor CT" << endl;
}
}
imprimeResult(geral);
geral.clear();
contador++;
cout << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment