NC222159. ChinoWithMates
描述
输入描述
The first line contain two positive integers
The next line contain integers indicates the personality characteristic value of the male guests.
Then the next line contain integers indicates the personality characteristic value of the female guests.
the final line only contain two integers
输出描述
Output an integer on a line to indicate the number of matching combinations.
示例1
输入:
5 5 1 2 3 4 5 1 2 3 4 5 1 20
输出:
24
说明:
For the first example, except that the male guest and the female guest do not meet the conditions, the other conditions are all legal, so the answer is .示例2
输入:
3 4 -1 -3 -5 -7 -6 -8 -9 9 9
输出:
1
说明:
For the second example, there is only a legal matching combination for male guest and female guest .C++ 解法, 执行用时: 63ms, 内存消耗: 4148K, 提交时间: 2021-05-26 00:10:11
#include<bits/stdc++.h> using namespace std; int n,m,i,j,l,r,t,k; long long s; double x,y; double a[100005],b[100005]; int main() { scanf("%d%d",&n,&m); for(i=0;i<n;i++) scanf("%lf",&a[i]); for(i=0;i<m;i++) scanf("%lf",&b[i]); scanf("%d%d",&l,&r); sort(b,b+m); for(i=0;i<n;i++) { if(a[i]>=0) { x=l*1.0/a[i]; y=r*1.0/a[i]; t=lower_bound(b,b+m,x)-b; k=upper_bound(b,b+m,y)-b; if(k<=t||y<b[0]||x>b[m-1]) continue; s=s+k-t; } else { x=r*1.0/a[i]; y=l*1.0/a[i]; t=lower_bound(b,b+m,x)-b; k=upper_bound(b,b+m,y)-b; if(k<=t||y<b[0]||x>b[m-1]) continue; s=s+k-t; } } printf("%lld",s); }