1. 程式人生 > >Codeforces956D. Contact ATC

Codeforces956D. Contact ATC

cto print sse none AS || sca clear tor

$n \leq 100000$個飛機在坐標軸上,給坐標給速度,坐標速度異號,還有一個風速在$[-w,w]$區間,$w$比最小的速度絕對值要小。由於風速不知道,所以問有多少對飛機可能在原點相遇。

思維定勢:$\frac{x_i}{v_i+v}=\frac{x_j}{v_j+v}$,$v$是風速,然後推下去,會推到一個三維偏序。。

沒有觀察題目性質。這個時間是關於風速單調而連續的,所以只要風速最小和風速最大這兩個東西求個逆序對就行了。

似乎卡精度,用了分數。

這種題要寫題解感覺最近腦子有點銹。。有沒有神犇願意幫忙除個銹啊QAQ

技術分享圖片
 1 #include<stdio.h>
 2 #include<string
.h> 3 #include<stdlib.h> 4 //#include<math.h> 5 //#include<queue> 6 //#include<vector> 7 #include<algorithm> 8 //#include<iostream> 9 //#include<assert.h> 10 using namespace std; 11 12 int n,w; 13 #define maxn 200011 14 15 struct frac 16 { 17 int a,b; 18 bool
operator < (const frac &x) const {return 1ll*a*x.b<1ll*b*x.a;} 19 bool operator == (const frac &x) const {return 1ll*a*x.b==1ll*b*x.a;} 20 }; 21 22 struct Poi{frac x,y; int z;}p[maxn]; 23 bool cmpx(const Poi &a,const Poi &b) {return b.x<a.x || (a.x==b.x && a.y<b.y);}
24 frac lisa[maxn]; int li=0; 25 26 struct BIT 27 { 28 int a[maxn],n; 29 void clear(int m) {n=m;} 30 void add(int x,int v) {for (;x<=n;x+=x&-x) a[x]+=v;} 31 int query(int x) {int ans=0; for (;x;x-=x&-x) ans+=a[x]; return ans;} 32 }t; 33 34 #define LL long long 35 int main() 36 { 37 scanf("%d%d",&n,&w); 38 for (int i=1,a,b;i<=n;i++) 39 { 40 scanf("%d%d",&a,&b); 41 if (a<0) p[i].x=(frac){-a,b-w},p[i].y=(frac){-a,b+w}; 42 else p[i].x=(frac){a,w-b},p[i].y=(frac){a,-w-b}; 43 lisa[++li]=p[i].y; 44 } 45 sort(lisa+1,lisa+1+li); 46 for (int i=1;i<=n;i++) p[i].z=lower_bound(lisa+1,lisa+1+li,p[i].y)-lisa; 47 48 sort(p+1,p+1+n,cmpx); 49 t.clear(n); 50 LL ans=0; 51 for (int i=1;i<=n;i++) 52 { 53 ans+=t.query(p[i].z); 54 t.add(p[i].z,1); 55 } 56 printf("%lld\n",ans); 57 return 0; 58 }
View Code

Codeforces956D. Contact ATC