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

版权声明:本文为博主原创文章,转载请标明原博客。 https://blog.csdn.net/sdau_fangshifeng/article/details/88371576

 题目链接:

http://codeforces.com/contest/1133/problem/D

D. Zero Quantity Maximization

You are given two arrays aa and bb, each contains nn integers.

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

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

Input

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

The second line contains nn integers a1, a2, ..., an (−109≤ai≤109).

The third line contains nn integers b1, b2 ..., bn (−109≤bi≤109).

Output

Print one integer — the maximum number of zeroes in array cc, if you choose dd 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

0

input

3 1 2 -1 -6 -12 6

output

3

Note

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

In the second example, we may choose d=−1/13.

In the third example, we cannot obtain any zero in array cc, no matter which dd we choose.

In the fourth example, we may choose d=6

 题目大意

 问题,给你一组数a[],和一组数b[]

有c[]=a[]*b+b[],,,,寻找满足条件的b,使得c[]等于0

问:哪种b的数量能够满足最多c[]=0,输出最多的数量。

思路:

令c[]=0,计算有多少种b,并记录每一种的数量,输出最多的数量

用pair< , > 表示不同的b,用map计数,

特殊处理:

ai=bi=0时,b可以为任意数

当需要判断两个数相相除的结果是否不同是,精度问题个能会困扰我们,

做题刚学的,使用pair<int , int > 表示分数,可以表示不同的分数,(不需要重载等于号的)

This is the codes:

#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define pppp cout<<endl;
#define EPS 1e-18
#define LL long long
#define ULL unsigned long long     //1844674407370955161
#define INT_INF 0x3f3f3f3f      //1061109567
#define LL_INF 0x3f3f3f3f3f3f3f3f //4557430888798830399
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf,sscanf, getchar, fgets之类的一起使用了。
const int dr[]= {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]= {-1, 1, 0, 0, -1, 1, -1, 1};
const int maxn=200000+10;
int a[maxn];
int b[maxn];
map<pair<int,int> ,int> mp;
int Gcd(int n,int m)
{
    if(!m)
        return n;
    return Gcd(m,n%m);
}
int main()
{
    int n,t;
    while(~scanf("%d",&n))
    {
        mp.clear();
        int cnt=0;//记录a[i]==b[i]==0 的对数
        for(int i=0;i<n;++i)
            scanf("%d",&a[i]);
        for(int i=0;i<n;++i)
        {
            scanf("%d",&b[i]);
            if(a[i]==0)
            {
                if(b[i]==0)
                    cnt++;
            }
            else
            {
                int gcd=Gcd(a[i],b[i]);//需要化简分数
                mp[make_pair(a[i]/gcd,b[i]/gcd)]++;
            }
        }
        map<pair<int,int>,int >::iterator it=mp.begin();
        int sum=0;
        for( ; it!=mp.end();++it)//寻找个数最多的
            sum=max(sum,it->second);
        printf("%d\n",sum+cnt);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sdau_fangshifeng/article/details/88371576