20200727T3 【NOIP2017提高A组模拟8.10】计算几何
Description
3 4 5 3 3 5 4 2 1 1 3 3
0 3
Solution
然而并不用long long。
考场上就是直接排序然后判断 80分
可以用它的单调递增用二分优化就过了
tip:作者发现自己菜得连二分都写不对了。调了一会。。
code
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #include<queue> 7 #include<vector> 8 #include<stack> 9 #include<set> 10 #include<deque> 11 #include<map> 12 using namespace std; 13 14 template <typename T> void read(T &x) { 15 x = 0; int f = 1; char c; 16 for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c == '-') f = -f; 17 for (; c >= '0' && c <= '9'; c = getchar()) x = 10 * x + c - '0' ; 18 x *= f; 19 } 20 template <typename T> void write(T x){ 21 if (x < 0) putchar('-'), x = -x; 22 if (x > 9) write(x / 10); 23 putchar(x % 10 + '0'); 24 } 25 template <typename T> void writeln(T x) { write(x); putchar('\n'); } 26 template <typename T> void writesn(T x) { write(x); putchar(' '); } 27 28 #define ll long long 29 #define inf 100000 30 #define next net 31 #define P 9999991 32 #define N 100010 33 #define mid ((l+r)>>1) 34 #define lson (o<<1) 35 #define rson (o<<1|1) 36 #define R register 37 #define debug puts("zxt") 38 39 int n, m , aa, bb; 40 int x[N ], y[N ]; 41 double k[N ], b[N ]; 42 signed main() 43 { 44 read(n); 45 for(R int i = 1; i <= n; i++) read(x[i]); 46 for(R int i = 1; i <= n; i++) read(y[i]); 47 sort(x + 1, x + n + 1); 48 sort(y + 1, y + n + 1); 49 for(R int i = 1; i <= n;i++) 50 { 51 k[i] = - 1.0 * y[i] / x[i]; 52 b[i] = 1.0 * y[i]; 53 } 54 read(m ); 55 while(m --) 56 { 57 read(aa); read(bb); 58 int l = 0, r = n; 59 while(l + 1 < r) 60 { 61 if(1.0 * aa * k[mid] + b[mid] <= (double)bb) l = mid; 62 else r = mid - 1; 63 } 64 if(1.0 * aa * k[l + 1] + b[l + 1] <= (double)bb) writeln(l + 1); 65 else writeln(l); 66 } 67 return 0; 68 }