首页 > 其他 > 详细

Codeforces Round #544 (Div. 3) D. Zero Quantity Maximization

时间:2019-03-08 15:52:33      阅读:196      评论:0      收藏:0      [点我收藏+]
D. Zero Quantity Maximization
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given two arrays ??a and ??b, each contains ??n integers.

You want to create a new array ??c as follows: choose some real (i.e. not necessarily integer) number ??d, and then for every ??[1,??]i∈[1,n] let ????:=??????+????ci:=d⋅ai+bi.

Your goal is to maximize the number of zeroes in array ??c. What is the largest possible answer, if you choose ??d optimally?

Input

The first line contains one integer ??n (1??21051≤n≤2⋅105) — the number of elements in both arrays.

The second line contains ??n integers ??1a1, ??2a2, ..., ????an (109????109−109≤ai≤109).

The third line contains ??n integers ??1b1, ??2b2, ..., ????bn (109????109−109≤bi≤109).

Output

Print one integer — the maximum number of zeroes in array ??c, if you choose ??d optimally.

Examples
input
Copy
5
1 2 3 4 5
2 4 7 11 3
output
Copy
2
input
Copy
3
13 37 39
1 2 3
output
Copy
2
input
Copy
4
0 0 0 0
1 2 3 4
output
Copy
0
input
Copy
3
1 2 -1
-6 -12 6
output
Copy
3
Note

In the first example, we may choose ??=2d=−2.

In the second example, we may choose ??=113d=−113.

In the third example, we cannot obtain any zero in array ??c, no matter which ??d we choose.

In the fourth example, we may choose ??=6d=6.

 

题目不难,更多的是关于心态的反思。

在比赛中遇到问题时,不应该慌乱,应该仔细再读一读题,在纸上把自己的思路写出来,检查有没有错误,不要想当然。

 

#include "bits/stdc++.h"

using namespace std;
const int maxn = 2e5 + 100;
typedef long long ll;

struct node {
    ll a, b;
};

bool operator<(node a, node b) {
    if (a.a != b.a) return a.a < b.a;
    return a.b < b.b;
}

map<node, ll> mp;

ll a[maxn], b[maxn];


int main() {
    //freopen("input.txt", "r", stdin);
    ll n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll gcd;
    node temp;
    ll tot = 0;
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        if (a[i] == 0 && b[i] != 0) {
            continue;
        } else if (a[i] != 0 && b[i] == 0) {
            temp.a = 0;
            temp.b = 0;
        } else if (a[i] == 0 && b[i] == 0) {
            tot++; //比赛时忽视了这种情况。。。
            continue;
        } else {
            gcd = __gcd(a[i], b[i]);
            a[i] /= gcd;
            b[i] /= gcd;
            if (a[i] < 0) {
                a[i] *= -1;
                b[i] *= -1;
            }
            temp.a = a[i];
            temp.b = b[i];
            //temp.a = min(a[i], b[i]);  //这样写会产生错误,比如a=3,b=4与a=4,b=3会归到一种情况,只需要在前面统一a[i]的符号就足够了
            //temp.b = max(a[i], b[i]);
        }
        mp[temp]++;
    }
    map<node, ll>::iterator it;
    it = mp.begin();
    ll ans = 0;
    while (it != mp.end()) {
        ans = max(ans, it->second);
        it++;
    }
    cout << ans + tot << endl;
    return 0;
}

 

Codeforces Round #544 (Div. 3) D. Zero Quantity Maximization

原文:https://www.cnblogs.com/albert-biu/p/10495715.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!