题意:一个三维空间中的一个立方体,每次给一条线,线所经过单位立方体被消去
最多一千条,问最终被消去多少个小块
因为只有一千条线,那么可以记录每个点是否消去过。对!可以map之 T!! L!! E!!
改成vetor式的hash 625ms慢慢的
//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")
//HEAD
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
//LOOP
#define FF(i, a, b) for(int i = (a); i < (b); ++i)
#define FD(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
//STL
#define SZ(V) (int)V.size()
#define PB push_back
#define EQ(a, b) (fabs((a) - (b)) <= 1e-10)
#define ALL(c) (c).begin(), (c).end()
//INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)
#define RS(s) scanf("%s", s)
//OUTPUT
#define WI(n) printf("%d\n", n)
#define WS(s) printf("%s\n", s)
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> VI;
const int INF = 100000000;
const double eps = 1e-10;
const int maxn = 220;
typedef pair<int, int> pii;
const int MOD = 1000003;
int n, m, num;
VI node[MOD + 10];
void init()
{
REP(i, MOD + 1)
node[i].clear();
}
int Insert(int h)
{
int hh = h % MOD;
int sz = node[hh].size();
REP(i, sz)
if (node[hh][i] == h)
return 0;
node[hh].PB(h);
return 1;
}
int main()
{
int T, a, b, ax[3];
char ch1, ch2;
RI(T);
while (T--)
{
num = 0;
int cnt = 0;
RII(n, m);
init();
REP(i, m)
{
CLR(ax, -1);
scanf(" %c", &ch1);
getchar();
RI(a), getchar(), scanf("%c", &ch2), getchar(), RI(b);
ax[ch1 - 'X'] = a - 1;
ax[ch2 - 'X'] = b - 1;
if (a > n || a <= 0 || b > n || b <= 0)
continue;
if (ax[0] == -1)
{
REP(j, n)
if (Insert(j * 1000000 + ax[1] * 1000 + ax[2])) cnt++;
}
else if (ax[1] == -1)
{
REP(j, n)
if (Insert(ax[0] * 1000000 + j * 1000 + ax[2])) cnt++;
}
else if (ax[2] == -1)
{
REP(j, n)
if (Insert(ax[0] * 1000000 + ax[1] * 1000 + j)) cnt++;
}
}
WI(cnt);
}
}