Last active
August 29, 2015 14:23
-
-
Save rogerioagjr/a96a8ba4379c03354941 to your computer and use it in GitHub Desktop.
Caça Tesouro
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 <algorithm> | |
#include <vector> | |
using namespace std; | |
#define MAXN 110 | |
typedef pair<int,int> ii; | |
int n, k, mapa[MAXN][MAXN]; | |
vector<ii> resp; | |
int main(){ | |
scanf("%d %d", &n, &k); // leio os valores de n e k | |
// para cada pista | |
for(int i=1; i<=k; i++){ | |
// declaro e leio os valores de x, y e d | |
int x, y, d; | |
scanf("%d %d %d", &x, &y, &d); | |
// e marco todas as posições que satisfazem às condições | |
for(int i=0; i<n; i++) | |
for(int j=0; j<n; j++) | |
if(abs(x-i)+abs(y-j)==d) mapa[i][j]++; | |
} | |
// guardo todas as casas qe foram apontadas em todas as pistas | |
for(int i=0; i<n; i++) | |
for(int j=0; j<n; j++) | |
if(mapa[i][j]==k) resp.push_back(ii(i, j)); | |
// se houver exatamente uma casa possível, imprimo suas coordenadas | |
if(resp.size()==1) printf("%d %d\n", resp[0].first, resp[0].second); | |
// caso contrário, imprimo uma linha com os números -1 -1 | |
else printf("-1 -1\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment