在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
Sample Output
1 2
题意:
先解释一下题目意思,
有许多Ax+B 的直线,求 max{ Ax+B }的部分,
也就是所有曲线在上方的部分;
那么我们可以先将直线按斜率排序,如果斜率相同,那么肯定是截距大的保留,因为小的直接被覆盖了;
画图可以发现-------> 每次保留两直线的交点,那么我们只需看横坐标的大小,来判断栈顶是pop还是压入栈;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 600005
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const int mod = 10000007;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-7
typedef pair<int, int> pii;
#define pi acos(-1.0)
inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
}
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }
int top, sk[maxn];
int ans[maxn];
struct node {
int a, b;
int id;
}eg[maxn];
int n;
bool cmp(node x, node y) {
if (x.a != y.a)return x.a > y.a;
else return x.b > y.b;
}
double cal(int i, int j) {
return (double)(eg[j].b - eg[i].b) / (double)(eg[i].a - eg[j].a);
}
bool com(int a, int b) {
return a < b;
}
int main()
{
//ios::sync_with_stdio(false);
rdint(n);
for (int i = 1; i <= n; i++) {
rdint(eg[i].a); rdint(eg[i].b);
eg[i].id = i;
}
sort(eg + 1, eg + 1 + n, cmp);
int tot = 0;
for (int i = 1; i <= n; i++) {
if (eg[i].a == eg[i - 1].a&&i!=1)continue;
while (top > 1 && cal(sk[top], i) >= cal(sk[top], sk[top - 1]))top--;
sk[++top] = i; ans[top] = eg[i].id;
}
sort(ans + 1, ans + 1 + top, com);
for (int i = 1; i <= top; i++)cout << ans[i] << ' ';
return 0;
}