P9914 题解
FurippuWRY · · 题解
样例给的提示比较少,于是自己造了一些。
设点的速度为
设有点
于是可以推测:对于
知道了这一点,那么就可以把每个点的横坐标或纵坐标乘上对应的速度,并寻找相等结果的个数,输出即可。
但是
需要稍微卡一下常,我这份代码能过,但有时候因为评测机的问题,会超 0.01~0.03s,可以打个快读快写优化一下。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, a, b, ans = 0;
multiset<ll> x;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for (ll i = 1; i <= n; ++i) {
cin >> a;
a *= i;//横坐标乘速度
if (a != 0) x.insert(a);//若不为 0,则加入集合中
}
for (ll i = 1; i <= m; ++i) {
cin >> b;
b *= i;//纵坐标乘速度
ans += x.count(b);//统计相等元素的个数。
}
cout << ans;
return 0;
}