bzoj1007 [HNOI2008]水平可见直线

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

Sample Output

1 2

 

正解:半平面交。这就是个板子。

 

 1 //It is made by wfj_2048~
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <cstring>
 5 #include <cstdlib>
 6 #include <cstdio>
 7 #include <vector>
 8 #include <cmath>
 9 #include <queue>
10 #include <stack>
11 #include <map>
12 #include <set>
13 #define inf (1LL<<40)
14 #define il inline
15 #define RG register
16 #define ll long long
17  
18 using namespace std;
19  
20 struct edge{ ll nt,to,dis; }g[1000010];
21  
22 ll no[110][110],f[110],head[30],cnt[30],dis[30],q[1000010],n,m,k,e,d,num;
23  
24 il ll gi(){
25     RG ll x=0,q=0; RG char ch=getchar(); while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
26     if (ch=='-') q=1,ch=getchar(); while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar(); return q ? -x : x;
27 }
28  
29 il void insert(RG ll from,RG ll to,RG ll dis){ g[++num]=(edge){head[from],to,dis},head[from]=num; return; }
30  
31 il ll spfa(){
32     RG ll h=0,t=1; for (RG int i=2;i<=m;++i) dis[i]=inf; dis[1]=0,q[t]=1;
33     while (h<t){
34     RG ll x=q[++h];
35     for (RG ll i=head[x];i;i=g[i].nt){
36         RG ll v=g[i].to; if (cnt[v]) continue;
37         if (dis[v]>dis[x]+g[i].dis) q[++t]=v,dis[v]=dis[x]+g[i].dis;
38     }
39     }
40     return dis[m];
41 }
42  
43 il void work(){
44     n=gi(),m=gi(),k=gi(),e=gi(); for (RG ll i=1;i<=e;++i){ RG ll u=gi(),v=gi(),w=gi(); insert(u,v,w),insert(v,u,w); }
45     d=gi(); for (RG ll i=1;i<=d;++i){ RG ll id=gi(),a=gi(),b=gi(); for (RG ll j=a;j<=b;++j) no[id][j]=1; }
46     for (RG ll i=1;i<=n;++i){
47     memset(cnt,0,sizeof(cnt)); for (RG ll p=1;p<=m;++p) for (RG ll q=1;q<=i;++q) if (no[p][q]){ cnt[p]=1; break; }
48     RG ll l=spfa(); if (l<inf) f[i]=i*l; else f[i]=inf;
49     for (RG ll j=1;j<i;++j){
50         memset(cnt,0,sizeof(cnt)); for (RG ll p=1;p<=m;++p) for (RG ll q=j+1;q<=i;++q) if (no[p][q]){ cnt[p]=1; break; }
51         RG ll l=spfa(); if (l<inf) f[i]=min(f[i],f[j]+(i-j)*l+k);
52     }
53     }
54     printf("%lld\n",f[n]); return;
55 }
56  
57 int main(){
58     work();
59     return 0;
60 }

 

posted @ 2017-02-10 21:51  wfj_2048  阅读(189)  评论(0编辑  收藏  举报