shjwudp

导航

 

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1007

解:直线的上表面一定是一个下凹的形状,那么按斜率排序后维护凸包即可。注意将斜率相同的直线特判一下,取B值大的

 1 /*
 2  * Problem:  
 3  * Author:  SHJWUDP
 4  * Created Time:  2015/6/9 星期二 13:36:54
 5  * File Name: 233.cpp
 6  * State: 
 7  * Memo: 
 8  */
 9 #include <iostream>
10 #include <cstdio>
11 #include <cstring>
12 #include <algorithm>
13 #include <cmath>
14 #include <vector>
15 
16 using namespace std;
17 
18 const double INF=0x7f7f7f7f;
19 const double eps=1e-7;
20 
21 const int MaxA=5e4+7;
22 
23 struct Data {
24     double A, B;
25     int id;
26     bool operator<(const Data& rhs) const {
27         if(fabs(A-rhs.A)<eps) return B>rhs.B;
28         return A<rhs.A;
29     }
30 } dt[MaxA];
31 
32 int N;
33 pair<int, double> stk[MaxA];
34 int top;
35 int main() {
36 #ifndef ONLINE_JUDGE
37     freopen("in", "r", stdin);
38     //freopen("out", "w", stdout);
39 #endif
40     while(~scanf("%d", &N)) {
41         for(int i=0; i<N; i++) {
42             scanf("%lf%lf", &dt[i].A, &dt[i].B);
43             dt[i].id=i+1;
44         }
45         sort(dt, dt+N);
46 
47         top=0;
48         stk[++top]=make_pair(0, -INF);
49         for(int i=1; i<N; i++) {
50             Data& u=dt[i];
51             if(u.A-dt[stk[top].first].A<eps) continue;
52             double tmp;
53             while(top) {
54                 pair<int, double>& x=stk[top];
55                 Data& d=dt[x.first];
56                 tmp=(u.B-d.B)/(d.A-u.A);
57                 if(tmp-x.second<eps) top--;
58                 else break;
59             }
60             stk[++top]=make_pair(i, tmp);
61         }
62         vector<int> vec(top);
63         for(int i=1; i<=top; i++) {
64             vec[i-1]=dt[stk[i].first].id;
65         }
66         sort(vec.begin(), vec.end());
67         for(int i=0; i<top; i++) {
68             printf("%d ", vec[i]);
69         }
70         puts("");
71     }
72     return 0;
73 }
View Code

 

posted on 2015-06-09 14:46  shjwudp  阅读(160)  评论(0编辑  收藏  举报