Ha terminado el concurso de diciembre, y aquí dejo la solución a uno de los problemas planteados:
Coin Flip
El enunciado es este:
Little Elephant was fond of inventing new games. After a lot of
research, Little Elephant came to know that most of the animals in the
forest were showing less interest to play the multi-player games.Little
Elephant had started to invent single player games, and succeeded in
inventing the new single player game named COIN FLIP.
In this game the player will use N coins numbered from 1 to N, and all the coins will be facing in "Same direction" (Either Head or Tail),which will be decided by the player before starting of the game.
The player needs to play N rounds.In the k-th round the player will flip the face of the all coins whose number is less than or equal to k. That is, the face of coin i will be reversed, from Head to Tail, or, from Tail to Head, for i ≤ k.
Elephant needs to guess the total number of coins showing a particular face after playing N rounds. Elephant really becomes quite fond of this game COIN FLIP, so Elephant plays G times. Please help the Elephant to find out the answer.
Podeis encontrar el enunciado completo aqui: Enunciado
La solución que he propuesto es la siguiente:
#include <cstdlib> #include <stdio.h> #include <cstdio> using namespace std; inline void fastRead(int *a){ register char c=0; while (c<33) c=getchar(); *a=0; while (c>33) { *a=*a*10+c-'0'; c=getchar(); } } int main(int argc, char *argv[]) { int T, G; fastRead(&T); for(int k=0; k<T; k++){ fastRead(&G); int games[G][3]; for(int i=0; i<G;i++){ for(int j=0; j<3;j++){ fastRead(&games[i][j]); } if(games[i][1]%2 == 0){ printf("%d\n", games[i][1]/2); }else{ if(games[i][0] == games[i][2]){ printf("%d\n", games[i][1]/2); }else{printf("%d\n", (games[i][1]/2)+1);} } } } return 0; }
Esta solución ha quedado la 129 de 2192 soluciones correctas. En comparación con la mejor solución, yo tengo una peor I/O, y aunque los dos nos hemos dado cuenta de que la clave era la comparación de los números de la entrada, el otro programador se ahorra una comparación que yo si hago, que posiblemente no sea necesaria. Para practicar de cara al concurso de diciembre intentaré hacer algunas practicas que hay en la web y las subire si salen bien.
No hay comentarios:
Publicar un comentario