Created
May 25, 2015 04:58
-
-
Save rogerioagjr/7abebf3a683a452bbe25 to your computer and use it in GitHub Desktop.
Feira de Bactérias
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
#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