1 条题解
-
1chrB LV 8 MOD @ 2017-10-30 21:08:45
排序XY轴从小到大一一对应,每条线段表示成截距式转一般式(x/x1+y/y1=1 ==> x*y1+y*x1=x1*y1)可以避免除法运算,判断方位用不等式,大于在哪边自己画图看,二分寻找临界边,讲的很烂,听不懂看代码。
蒟蒻刘宝宝我只会递归二分,又长又丑。自己画图好好领会一下。#include<bits/stdc++.h> using namespace std; typedef unsigned long long ll; ll xx[400100],yy[400100]; ll n,m,x,y; inline bool cmp(int u,int v){return u<v;} inline void work(int l,int r) { int mid=(l+r+1)>>1; ll e1=yy[mid]*x+xx[mid]*y,e2=yy[mid]*xx[mid]; ll e3=yy[mid-1]*x+xx[mid-1]*y,e4=yy[mid-1]*xx[mid-1]; if(e1==e2) {printf("%d\n",mid);return;} if(e1<e2&&e3>=e4) {printf("%d\n",mid-1);return;} else if(e1>e2&&e3>e4) {work(mid+1,r);return;} else if(e1<=e2) {work(l,mid-1);return;} } int main() { cin>>n; for(int i=1;i<=n;i++)scanf("%d",&xx[i]); for(int i=1;i<=n;i++)scanf("%d",&yy[i]); sort(xx+1,xx+n+1,cmp); sort(yy+1,yy+n+1,cmp); cin>>m; ll p1=xx[1]*yy[1],p2=xx[n]*yy[n]; while(m--) { scanf("%d%d",&x,&y); if(yy[1]*x+xx[1]*y<p1){printf("0\n");continue;} if(yy[1]*x+xx[1]*y==p1){printf("1\n");continue;} if(yy[n]*x+xx[n]*y>=p2){printf("%d\n",n);continue;} work(1,n); } return 0; }
- 1