Skip to content

Instantly share code, notes, and snippets.

@rogerioagjr
Created June 8, 2016 11:52
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/a6293b700e292f7611f1642e5c14de79 to your computer and use it in GitHub Desktop.
Save rogerioagjr/a6293b700e292f7611f1642e5c14de79 to your computer and use it in GitHub Desktop.
Lâmpadas do hotel
// Lâmpadas do hotel - F1P2 - OBI 2016
// Rogério Júnior
// Complexidade: O(1)
#include <cstdio>
int ia, ib, fa, fb, resp;
int main(){
scanf("%d %d %d %d", &ia, &ib, &fa, &fb);
// se os estados inicial e final de B forem diferentes
if(fb!=ib){
// aperto o interruptor 2
// então aumento 1 em resp
resp++;
// e troco o estado da lâmpada A
ia=(!ia);
}
// se os estados inicial e final de A forem diferentes
if(ia!=fa) resp++; // aumento 1 em resp
// por fim, imprimo o valor de resp
printf("%d\n", resp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment