按A从小到大排序然后用栈解决.
--------------------------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 50009;
struct L {
int A, B, id;
inline void Read(int p) {
scanf("%d%d", &A, &B);
id = p;
}
bool operator < (const L &o) const {
return A < o.A || (A == o.A && B > o.B);
}
} S[maxn];
int N, sta[maxn], top = 0;
bool ans[maxn];
bool check(int a, int b, int c) {
return (ll) (S[b].A - S[c].A) * (S[b].B - S[a].B) >= (ll) (S[c].B - S[b].B) * (S[a].A - S[b].A);
}
int main() {
scanf("%d", &N);
for(int i = 0; i < N; i++)
S[i].Read(i);
sort(S, S + N);
sta[top = 0] = 0;
for(int i = 1; i < N; i++) {
if(S[i].A == S[sta[top]].A)
continue;
while(top && check(sta[top - 1], sta[top], i)) top--;
sta[++top] = i;
}
memset(ans, 0, sizeof ans);
for(; ~top; top--)
ans[S[sta[top]].id] = true;
for(int i = 0; i < N; i++)
if(ans[i]) printf("%d ", i + 1);
puts("");
return 0;
}
--------------------------------------------------------------------
1007: [HNOI2008]水平可见直线
Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4676 Solved: 1725
[Submit][Status][Discuss]
Description
在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为可见的,否则Li为被覆盖的.
例如,对于直线:
L1:y=x; L2:y=-x; L3:y=0
则L1和L2是可见的,L3是被覆盖的.
给出n条直线,表示成y=Ax+B的形式(|A|,|B|<=500000),且n条直线两两不重合.求出所有可见的直线.
Input
第一行为N(0 < N < 50000),接下来的N行输入Ai,Bi
Output
从小到大输出可见直线的编号,两两中间用空格隔开,最后一个数字后面也必须有个空格
Sample Input
3
-1 0
1 0
0 0
-1 0
1 0
0 0
Sample Output
1 2