原题:ARC076E
洛谷上 UKE,所以到原网交,21 个点只对了 17 个,蒟蒻跪下求大佬帮忙 DEBUG!
源码呈上:
#include <iostream>
#include <vector>
#include <array>
#include <stack>
#include <algorithm>
using std::ios, std::cin, std::cout, std::endl;
using std::vector, std::stack, std::pair, std::array;
using std::sort, std::swap, std::make_pair;
using number = long long;
const int MAXN = 100005;
vector< pair<number, number> > have_it;
vector< pair<number, number> > dot_location;
stack<number> check_stack;
array<bool, MAXN> visited;
number r, c, n;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> r >> c >> n;
for (int i = 0; i < n; i++) {
number x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 != 0 || x1 != r || y1 != 0 || y1 != c) {
i--;
n--;
} else if (x2 != 0 || x2 != r || y2 != 0 || y2 != c) {
i--;
n--;
}
number loc1 = 0, loc2 = 0;
if (y1 == 0) {
loc1 = x1;
} else if (x1 == r) {
loc1 = r + y1;
} else if (y1 == c) {
loc1 = r * 2 + c - x1;
} else if (x1 == 0) {
loc1 = 2 * (r + c) - y1;
}
if (y2 == 0) {
loc2 = y2;
} else if (x2 == r) {
loc2 = r + y2;
} else if (y2 == c) {
loc2 = r * 2 + c - x2;
} else if (x2 == 0) {
loc2 = 2 * (r + c) - y2;
}
have_it.push_back(make_pair(loc1, loc2));
}
for (int i = 0; i < n; i++) {
dot_location.push_back(make_pair(have_it[i].first, static_cast<number>(i)));
dot_location.push_back(make_pair(have_it[i].second, static_cast<number>(i)));
}
sort(dot_location.begin(), dot_location.end());
for (int i = 0; i < 2 * n; i++) {
pair<number, number> get = dot_location[i];
if (!visited[get.second]) {
check_stack.push(get.second);
visited[get.second] = true;
} else {
if (check_stack.top() != get.second) {
cout << "NO" << endl;
return 0;
}
check_stack.pop();
}
}
cout << "YES" << endl;
return 0;
}
快快快!