Cod sursa(job #2142082)

Utilizator Teodor.mTeodor Marchitan Teodor.m Data 24 februarie 2018 18:38:17
Problema Zota & Chidil Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <bits/stdc++.h>
using namespace std;

ifstream in("zc.in");
ofstream out("zc.out");

int main() {

	int n, m; in >> n >> m;

	vector< pair< int, int > >capcane(n);
	for(auto& it: capcane)in >> it.first >> it.second;

	pair< int, int > currentPosition = make_pair(0, 0);
	int ans = 0;

	for(int i = 1; i <= m; ++i) {
		char direction;
		int steps;

		in >> direction >> steps;

		int nx, ny;
		if(direction == 'N') {
			nx = 0;
			ny = 1;
		} else {
			if(direction == 'E') {
				nx = 1;
				ny = 0;
			} else {
				if(direction == 'S') {
					nx = 0;
					ny = -1;
				} else {
					nx = -1;
					ny = 0;
				}
			}
		}

		while(steps) {
			currentPosition.first += nx;
			currentPosition.second += ny;
			//out << currentPosition.first << " " << currentPosition.second << '\n';

			for(auto it: capcane) {
				int manhattanDist = abs(currentPosition.first - it.first) + abs(currentPosition.second - it.second);

				if(manhattanDist <= 2) {
					ans++;
					//out << currentPosition.first << " " << currentPosition.second << " " << it.first << " " << it.second << " " << manhattanDist << '\n';
				}
			}
			steps--;
		}
	}

	out << ans;

	in.close(); out.close();

	return 0;
}