列表

详情


NC222159. ChinoWithMates

描述

Chino held a blind date event, there are male guests and female guests attending.

The personality characteristic value of each person can be represented by an integer, the personality characteristic value of the  male guest is a_i, and the personality characteristic value of the female guest is b_j.
Chino believes that when the calculation result of the personality characteristic values of two people in a certain range , the personality of two person is suitable each of them.

Chino would like to know how many matching combinations possible satisfied personality suitability between male and female guests.

输入描述

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 {5} and the female guest {5} do not meet the conditions, the other conditions are all legal, so the answer is {25-1=24}.

示例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 {1} and female guest {4}

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

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);
}

上一题