这道题刚开始以为是求凸包(convex hull),后来发现那样把最小的边界点也统计进去了。
所以最终的做法只是按x排序,再对每个点扫描判断(是否存在x,y都不小于它的点)。
thestoryofsnow | 1828 | Accepted | 572K | 1563MS | C++ | 1405B |
/*
ID: thestor1
LANG: C++
TASK: poj1828
*/
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <limits>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cassert>
using namespace std;
const int MAXN = 50000;
class Point{
public:
int x, y;
Point() {}
Point(int x, int y) : x(x), y(y) {}
inline bool operator <(const Point &p) const {
return x <= p.x;
}
};
int main()
{
Point points[MAXN];
int N;
while (scanf("%d", &N) && N)
{
for (int i = 0; i < N; ++i)
{
scanf("%d%d", &points[i].x, &points[i].y);
}
sort(points, points + N);
// printf("[debug]points(%d):\n", N);
// for (int i = 0; i < N; ++i)
// {
// printf("%d,%d\t", points[i].x, points[i].y);
// }
// printf("\n");
int cnt = 0;
for (int i = 0; i < N; ++i)
{
bool isKing = true;
// there may be points with the same x value on the left
// need to check them as well (for y)
for (int j = i - 1; j >= 0 && points[j].x == points[i].x; j--)
{
if (points[j].y >= points[i].y)
{
isKing = false;
break;
}
}
for (int j = i + 1; j < N; ++j)
{
if (points[j].y >= points[i].y)
{
isKing = false;
break;
}
}
if (isKing)
{
cnt++;
}
}
printf("%d\n", cnt);
}
return 0;
}