[URI ONLINE JUDGE] – 1901 – Butterflies

Link: https://www.urionlinejudge.com.br/judge/en/problems/view/1901

 

The forests of planet called Binox have several rare species of butterflies. Bino is a butterfly hunter and he wants collect the max of different species of butterflies. The forest of Binox is represented by a square grid of size NxN. Each cell of the grid can have one butterfly. The image below represents the first example of input. The species collected were: 1, 2, 3, 4 and 8.

Your task is determine the amount of species of butterflies, which Bino is able to collect, and the only information that you have is the map of the forest and all places visited by Bino. For an unknown reason, Bino always searches in the 2*N positions in the forest.

Input

The input consists of multiples rows. The first row have an integer N (0 < N ≤ 200) representing the size of the forest. The following N rows have N integers Kij (0 < Kij ≤ 1000) each one representing one butterfly specie. The following N*2 rows, each row have 2 integers, representing the cells visited by Bino.

Output

Print out one row with an amount of different species which Bino collected.

Input Samples Output Samples
3
1 1 2
2 3 4
8 7 1
1 1
1 2
2 1
2 2
2 3
3 1
5

solution:

 

<br />#include <bits/stdc++.h>
#define D(x) cout << #x " = " << (x) << endl
#define endl '\n'

using namespace std;

int main() {
ios_base::sync_with_stdio(false);cin.tie(NULL);
long long n;
while (cin >> n) {
set<int> seen;
vector<vector<int> > g(n, vector<int>(n));
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
cin >> g[i][j];

int x, y;
for (int i = 0; i < 2 * n; ++i) {
cin >> x >> y;
seen.insert(g[x - 1][y - 1]);
}
cout << seen.size() << endl;
}
return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s