其实是维护一个类似下凸壳的东西?画图后发现其实斜率是单调递增的,交点的横坐标也是单调递增的,所以排序一下搞个单调栈来做就可以了……

  看了hzwer的做法……

 1 /**************************************************************
 2     Problem: 1007
 3     User: Tunix
 4     Language: C++
 5     Result: Accepted
 6     Time:252 ms
 7     Memory:2812 kb
 8 ****************************************************************/
 9  
10 //BZOJ 1007
11 #include<cstdio>
12 #include<cmath>
13 #include<cstdlib>
14 #include<algorithm>
15 #define F(i,j,n) for(int i=j;i<=n;++i)
16 using namespace std;
17 const double eps=1e-8;
18 const int N=50001;
19 struct data{double a,b;int n;}l[N],st[N];
20 bool ans[N];
21 int top,n;
22 inline bool cmp(data a,data b){
23     if (fabs(a.a-b.a)<eps) return a.b<b.b;
24     return a.a<b.a;
25 }
26 double crossx(data x1,data x2){
27     return (x2.b-x1.b)/(x1.a-x2.a);
28 }
29 void insert(data a){
30     while(top){
31         if (fabs(st[top].a-a.a)<eps) top--;
32         else if(top>1 && crossx(a,st[top-1])<=crossx(st[top],st[top-1]))
33             top--;
34         else break;
35     }
36     st[++top]=a;
37 }
38 void work(){
39     F(i,1,n) insert(l[i]);
40     F(i,1,top) ans[st[i].n]=1;
41     F(i,1,n) if (ans[i]) printf("%d ",i);
42 }
43 int main(){
44     scanf("%d",&n);
45     F(i,1,n){
46         scanf("%lf%lf",&l[i].a,&l[i].b);
47         l[i].n=i;
48     }
49     sort(l+1,l+n+1,cmp);
50     work();
51     return 0;
52 }
53 
View Code

相关文章:

  • 2021-12-18
  • 2021-07-16
  • 2021-08-10
  • 2021-06-10
  • 2022-01-06
  • 2021-10-27
  • 2022-01-27
  • 2021-07-07
猜你喜欢
  • 2022-01-03
  • 2021-08-17
  • 2022-02-27
  • 2021-08-16
  • 2022-12-23
  • 2021-11-17
相关资源
相似解决方案