题目链接:http://codeforces.com/problemset/problem/734/D
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
using namespace std;
typedef long long LL;
const int maxn = 500000 + 20;
LL xx0, yy0;
struct node
{
char ch;
LL x, y;
node() {}
node(char cc, LL xx, LL yy) : ch(cc), x(xx), y(yy)
{}
bool operator < (const struct node & rhs) const
{
LL dis = (x - xx0) * (x - xx0) + (y - yy0) * (y - yy0);
LL dis2 = (rhs.x - xx0) * (rhs.x - xx0) + (rhs.y - yy0) * (rhs.y - yy0);
return dis < dis2;
}
} arr[maxn];
vector<struct node>pos[66];
int main()
{
int n;
cin >> n;
cin >> xx0 >> yy0;
for (int i = 1; i <= n; ++i)
{
cin>>arr[i].ch;
cin >> arr[i].x >> arr[i].y;
}
sort(arr + 1, arr + 1 + n);
for (int i = 1; i <= n; ++i)
{
int face = 0;
if (arr[i].x == xx0 && arr[i].y > yy0)
face = 1;
else if (arr[i].x < xx0 && arr[i].y > yy0 && arr[i].x + arr[i].y == xx0 + yy0)
face = 2;
else if (arr[i].y == yy0 && arr[i].x < xx0)
face = 3;
else if (arr[i].x < xx0 && arr[i].y < yy0 && arr[i].x - arr[i].y == xx0 - yy0)
face = 4;
else if (arr[i].x == xx0 && arr[i].y < yy0)
face = 5;
else if (arr[i].x > xx0 && arr[i].y < yy0 && arr[i].x + arr[i].y == xx0 + yy0)
face = 6;
else if (arr[i].y == yy0 && arr[i].x > xx0)
face = 7;
else if (arr[i].x > xx0 && arr[i].y > yy0 && arr[i].x - arr[i].y == xx0 - yy0)
face = 8;
if (pos[face].size() != 0)
continue;
pos[face].push_back(arr[i]);
}
// cout << "fff" << endl;
for (int i = 1; i <= 8; ++i)
{
if ((i == 1 || i == 5) && pos[i].size() && (pos[i][0].ch == 'Q' || pos[i][0].ch == 'R'))
{
printf("YES\n");
return 0;
}
else if ((i == 2 || i == 6) && pos[i].size() && (pos[i][0].ch == 'Q' || pos[i][0].ch == 'B'))
{
printf("YES\n");
return 0;
}
else if ((i == 3 || i == 7) && pos[i].size() && (pos[i][0].ch == 'Q' || pos[i][0].ch == 'R'))
{
printf("YES\n");
return 0;
}
else if ((i == 4 || i == 8) && pos[i].size() && (pos[i][0].ch == 'B' || pos[i][0].ch == 'Q'))
{
printf("YES\n");
return 0;
}
}
printf("NO\n");
return 0;
}
模拟+读题表示用翻译。。。
思路:结构体排序,找离女王最近的八个点。