Area of Polycubes poj 3792


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>   
#include <map>
#include <string>  
#include <climits> 
#include <set>
#include <string> 
#include <sstream>
#include <utility>
#include <ctime>
 
using std::priority_queue;
using std::vector;
using std::swap;
using std::stack;
using std::sort;
using std::max;
using std::min;
using std::pair;
using std::map;
using std::string;
using std::cin;
using std::cout;
using std::set;
using std::queue;
using std::string;
using std::istringstream;
using std::make_pair;
using std::greater;

int move_x[6] = {-1, 0, 1, 0, 0, 0};
int move_y[6] = {0, -1, 0, 1, 0, 0};
int move_z[6] = {0, 0, 0, 0, -1, 1};

struct NODE
{
	int x, y, z;
	friend bool operator <(const NODE &op1, const NODE &op2)
	{
		if(op1.x == op2.x)
		{
			if(op1.y == op2.y)
				return op1.z < op2.z;
			return op1.y < op2.y;
		}
		return op1.x < op2.x;
	}
};

set<NODE> st;

int main()
{
	int n_case(0), T;
	scanf("%d", &T);
	while(T--)
	{
		int n;
		scanf("%d", &n);
		int ans = n*3;
		int flag = -1;
		NODE t1, t2;
		st.clear();
		scanf("%d,%d,%d", &t1.x, &t1.y, &t1.z);
		st.insert(t1);
		for(int i = 2; i <= n; ++i)
		{
			scanf("%d,%d,%d", &t1.x, &t1.y, &t1.z);
			if(flag == -1 && st.find(t1) != st.end())
				flag = i;
			if(flag == -1)
			{
				int count = 0;
				for(int j = 0; j < 6; ++j)
				{
					t2 = t1;
					t2.x += move_x[j];
					t2.y += move_y[j];
					t2.z += move_z[j];
					if(st.find(t2) != st.end())
						++count;
				}
				if(count)
					ans -= count;
				else
					flag = i;
				st.insert(t1);
			}
		}
		if(flag != -1)
			printf("%d NO %d\n", ++n_case, flag);
		else
			printf("%d %d\n", ++n_case, ans*2);
	}
	return 0;
}


你可能感兴趣的:(Area of Polycubes poj 3792)