Codeforces Round #544 (Div. 3) D

Posted dyloder

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #544 (Div. 3) D相关的知识,希望对你有一定的参考价值。

题目链接:D. Zero Quantity Maximization

#include <bits/stdc++.h>
using namespace std;
#define maxn 200005
#define LL long long
#define pii pair<LL,LL>
map<pair<LL,LL>,LL>mp,mpp;
LL a[maxn],b[maxn];
LL gcd(LL a,LL b){
    return b?gcd(b,a%b):a;
}
int main(){
   LL n;
   scanf("%lld",&n);
   for(LL j=0;j<n;j++){
      scanf("%lld",&a[j]);
   }
   for(LL k=0;k<n;k++){
      scanf("%lld",&b[k]);
   }
   LL mx = 0,ans = 0;
   for(LL j=0;j<n;j++){
      LL z = gcd(abs(a[j]),abs(b[j]));
      if(b[j]<0){
         a[j] = -a[j];
         b[j] = -b[j];
      }
      if(a[j]==0){
         if(b[j]==0) ans++;
         continue;
      }
      if(b[j]==0){
           mp[make_pair(1LL*0,1LL*0)]++;
           mx = max(mx, mp[make_pair(1LL*0,1LL*0)]);
           continue;
      }
      mp[make_pair(a[j]/z,b[j]/z)]++;
      mx = max(mx, mp[make_pair(a[j]/z,b[j]/z)]);
   }
   printf("%lld
",mx+ans);
}

 

以上是关于Codeforces Round #544 (Div. 3) D的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #544 (Div. 3) C. Balanced Team [暴力剪枝]

Codeforces Round #544 (Div. 3) dp + 双指针

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)

背包DP || Codeforces 544C Writing Code

Codeforces Round #726 (Div. 2) B. Bad Boy(贪心)