Skip to content

Instantly share code, notes, and snippets.

@rogerioagjr
Created May 25, 2015 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogerioagjr/7abebf3a683a452bbe25 to your computer and use it in GitHub Desktop.
Save rogerioagjr/7abebf3a683a452bbe25 to your computer and use it in GitHub Desktop.
Feira de Bactérias
#include <cstdio>
#include <math.h> // biblioteca para usar a função log10
/*
Para resolver este problema basta encontrar um meio
de comparar valores que em tese podem ser muito altos,
como por exemplo : 2000 ^ 5000; Esta comparação pode ser
feita usando logaritmos, visto que o maior
valor obtido com uso de log é : log(2000) ^ 5000 = 5000 * log(2000) = 16505.1499783;
*/
int n,id;
double max_atual,d,c,res; // maxi é iniciada com 0.0; perceba que as variáveis devem ser do tipo double
int main() {
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%lf %lf", &d, &c);
res = c * log10(d);
// comparo se o novo resultado é maior que max_atual
// se for, a varivel id recebe o numero da nova bactéria
if(res > max_atual){
max_atual = res;
id = i;
}
}
printf("%d\n",id);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment