Skip to content

Instantly share code, notes, and snippets.

@cyberpirate92
Created February 24, 2017 15:35
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 cyberpirate92/67b17cb87f450c8dca647a3988ea04b4 to your computer and use it in GitHub Desktop.
Save cyberpirate92/67b17cb87f450c8dca647a3988ea04b4 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
int main() {
int T, n, q, i;
vector< vector<int> > field;
cin>>T;
for(int I=0; I<T; I++) {
field.clear();
cin>>n>>q;
for(i=0; i<n; i++) {
vector<int> row(3);
fill(row.begin(), row.end(), 0);
field.push_back(row);
}
for(i=0; i<q; i++) {
int x, y;
cin>>x>>y;
field[x-1][y-1] = 1;
}
/*// debug ----------
cout <<endl << " ------ " <<endl;
for(i=0; i<field.size(); i++) {
for(int j=0; j<field[i].size(); j++) {
cout << field[i][j] << "\t";
}
cout << endl;
}*/
int count;
for(i=0; i<n-1; i++) {
count = 3;
for(int j=0; j<3; j++) {
if(field[i][j] != 1) {
if(j==0) {
if(field[i+1][j] != 1 || field[i+1][j+1] != 1) {
count--;
}
}
else if(j==1) {
if(field[i+1][j-1] != 1 || field[i+1][j] != 1 || field[i+1][j+1] != 1) {
count--;
}
}
else {
if(field[i+1][j-1] != 1 || field[i+1][j] != 1) {
count--;
}
}
}
}
if(count == 3) {
break;
}
}
cout << i+1 << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment