Skip to content

Instantly share code, notes, and snippets.

@lidaobing
Created July 2, 2010 02:57
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 lidaobing/460857 to your computer and use it in GitHub Desktop.
Save lidaobing/460857 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <sstream>
#include <cstdio>
#include <set>
using namespace std;
#define FORI for(int i = 0; i < n; ++i)
#define FORJ for(int j = 0; j < n; ++j)
#define FOR(i, n) for(int (i) = 0; (i) < (n); ++(i))
typedef long long LL;
int n;
class A {
public:
int n;
int m;
int a[20][2];
int check(int b[10][10]) {
FOR(i, m) {
if(!b[a[i][0]][a[i][1]]) {
return 0;
}
}
return 1;
}
void printlines( vector<pair<int, int> >& lines) {
FOR(i, lines.size()) {
cout << '(' << lines[i].first << ',' << lines[i].second << ") ";
}
cout << endl;
}
void resolve() {
int count = 0;
int lines[200][2] = {0};
int b[10][10] = {0};
int t[5][2] = {{0,0}, {1, 0}, {0, 1}, {0, -1}, {-1, 0}};
int idx = 0;
lines[0][0] = n/2;
lines[0][1] = n/2;
int res = 0;
while(idx >= 0) {
//printlines(lines);
//cerr << lines.size() << endl;
int x = lines[idx][0];
int y = lines[idx][1];
b[x][y]++;
b[n-x][n-y] = b[x][y];
if(x == 0 or y == 0 or x == n or y == n) {
res += check(b);
--idx;
b[x][y] = 0;
b[n-x][n-y] = 0;
continue;
}
// if(x < 0 or y < 0 or x > n or y > n) {
// lines.pop_back();
// continue;
// }
//cout << x << y << b[x][y] << endl;
if(b[x][y] >= 5) {
--idx;
b[x][y] = 0;
b[n-x][n-y] = 0;
continue;
}
if(idx == 0 and b[x][y] >= 3) {
--idx;
b[x][y] = 0;
b[n-x][n-y] = 0;
continue;
}
int idx2 = b[x][y];
int nx = x + t[idx2][0];
int ny = y + t[idx2][1];
if(nx < 0 or ny < 0 or nx > n or ny > n) continue;
if(b[nx][ny]) continue;
idx++;
lines[idx][0] = nx;
lines[idx][1] = ny;
//cout << nx << ' ' << ny << endl;
}
cout << res*2 << endl;
}
void foo() {
scanf("%d%d", &n, &m);
n *= 2;
FOR(i, m) {
scanf("%d%d", &a[i][0], &a[i][1]);
}
resolve();
return;
}
};
int main() {
A().foo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment