题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1007
题意:给出一些直线。从Y轴正方向无穷远处向下看能看到哪些?
思路:如下图,首先将直线按照斜率升序排序,我们维护一个单调的栈,栈顶top,设X(i,j)表示i和j直线交点的横坐标,那么X(top,top-1)>=X(i,top)时top可以被top-1和i完全覆盖。比如下图,首先我们将1和2压入栈中。对于3,我们发现X(2,1)>=X(3,2),那么此时显然2被1和3完全覆盖;进而将3压入栈中;对于4,X(3,1)>=X(4,3),因此3被4和1完全覆盖,将3删掉,压入4。最后剩下1和4。
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <map>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define Len(x) x.length()
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define FOR0(i,x) for(i=0;i<x;i++)
#define FOR1(i,x) for(i=1;i<=x;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FORL0(i,a) for(i=a;i>=0;i--)
#define FORL1(i,a) for(i=a;i>=1;i--)
#define FORL(i,a,b)for(i=a;i>=b;i--)
#define rush() int CC;for(scanf("%d",&CC);CC--;)
#define Rush(n) while(scanf("%d",&n)!=-1)
using namespace std;
void RD(int &x){scanf("%d",&x);}
void RD(i64 &x){scanf("%I64d",&x);}
void RD(u64 &x){scanf("%I64u",&x);}
void RD(u32 &x){scanf("%u",&x);}
void RD(double &x){scanf("%lf",&x);}
void RD(int &x,int &y){scanf("%d%d",&x,&y);}
void RD(i64 &x,i64 &y){scanf("%I64d%I64d",&x,&y);}
void RD(u32 &x,u32 &y){scanf("%u%u",&x,&y);}
void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}
void RD(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void RD(i64 &x,i64 &y,i64 &z){scanf("%I64d%I64d%I64d",&x,&y,&z);}
void RD(u32 &x,u32 &y,u32 &z){scanf("%u%u%u",&x,&y,&z);}
void RD(double &x,double &y,double &z){scanf("%lf%lf%lf",&x,&y,&z);}
void RD(char &x){x=getchar();}
void RD(char *s){scanf("%s",s);}
void RD(string &s){cin>>s;}
void PR(int x) {printf("%d\n",x);}
void PR(int x,int y) {printf("%d %d\n",x,y);}
void PR(i64 x) {printf("%lld\n",x);}
void PR(u32 x) {printf("%u\n",x);}
void PR(u64 x) {printf("%I64u\n",x);}
void PR(double x) {printf("%.10lf\n",x);}
void PR(char x) {printf("%c\n",x);}
void PR(char *x) {printf("%s\n",x);}
void PR(string x) {cout<<x<<endl;}
const i64 inf=((i64)1)<<60;
const int mod=10007;
const double dinf=1e50;
const int INF=1000000006;
const int N=50005;
struct point
{
double A,B;
int id,flag;
void get()
{
RD(A,B);
flag=0;
}
};
point a[N];
int st[N],top;
int cmp(point a,point b)
{
if(a.A==b.A) return a.B>b.B;
return a.A<b.A;
}
double cross(point a,point b)
{
return (a.B-b.B)/(b.A-a.A);
}
int n;
int main()
{
Rush(n)
{
int i;
FOR1(i,n) a[i].get(),a[i].id=i;
sort(a+1,a+n+1,cmp);
top=0;
st[++top]=1;
for(i=2;i<=n;i++) if(a[i].A!=a[i-1].A)
{
while(top>=2&&cross(a[st[top]],a[st[top-1]])>=cross(a[st[top]],a[i]))
{
top--;
}
st[++top]=i;
}
vector<int> V;
FOR1(i,top) V.pb(a[st[i]].id);
sort(V.begin(),V.end());
FOR0(i,SZ(V)) printf("%d ",V[i]);
}
return 0;
}