POJ_2766_Laserbox_CE

#include<iostream>
//#include<sstream>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#pragma warning(disable:4996)
using std::cin;
using std::cout;
using std::endl;
//using std::stringstream;
using std::string;
using std::vector;
using std::list;
using std::pair;
using std::set;
using std::map;
using std::stack;
using std::queue;
vector<pair<int, int> >increment{ { -1,0 },{ 0,1 },{ 1,0 },{ 0,-1 } };
class Position
{
private:
int row;
int column;
int direction;
public:
Position(const int &r, const int &c, const int &di)
{
row = r;
column = c;
direction = di;
}
bool move(const vector<vector<bool> >&board)
{
if (row >= 0 && row < board.size() && column >= 0 && column < board.size())
{
//如果当前所在位置上有转向器
if (board[row][column])
{
//把方向调到右
direction = (direction + 1) % 4;
}
//沿着当前方向移动一格
row += increment[direction].first;
column += increment[direction].second;
return true;
}
return false;
}
bool operator==(Position tmp)
{
if (row == tmp.row&&column == tmp.column&&direction == tmp.direction)
{
return true;
}
return false;
}
void print(const int &n)
{
if (row >= 0 && row < n)
{
cout << row + 1 << ' ' << '0' << endl;
}
else
{
cout << '0' << ' ' << column+1 << endl;
}
}
};
int main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int T;
while (cin >> T)
{
while (T--)
{
int n; cin >> n;
vector<vector<bool> >board(n, (vector<bool>)n);
cin >> n;
while (n--)
{
int row, column; cin >> row >> column;
board[row-1][column-1] = true;
}
int row, column, direction;
cin >> row >> column;
if (row == board.size()+1)
{
row-=2;
direction = 0;
}
else if (!row)
{
row++;
direction = 2;
}
if (column == board.size()+1)
{
column-=2;
direction = 3;
}
else if (!column)
{
column++;
direction = 1;
}
Position curpos{ row,column,direction };
auto save = curpos;
while (curpos.move(board))
{
if (save == curpos)
{
break;
}
}
if (save == curpos)
{
cout << "0 0" << endl;
}
else
{
curpos.print(board.size());
}
}
}
return 0;
}

你可能感兴趣的:(list,poj)