Judge:https://vjudge.net/problem/UVA-11134
题意:在n*n的棋盘上放n个车,使所有的车不相互攻击,输出一个解或“IMPOSSIBLE”。注意此题的解并不是唯一的,所以如果你样例没通过是正常的。
首先,磁体不是八皇后问题,行和列是无关的,因此可以把行和列分开来做。
把各个区间排一遍序,然后放车的时候尽量往左放即可。
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct SInv {
int iIndex;
int iLeft, iRight;
};
struct SPoint {
int x, y;
};
SInv g_arrInvX