D. Zero Quantity Maximization ( Codeforces Round #544 (Div. 3) )
题意:
给你 整形数组a 和 整形数组b ,要你c[i] = d * a[i] + b[i], 求 在c[i]=0的时候 相同的d的数量 最多能有几个。
思路:
1. 首先打开别人的博客。
2..........
一开始尝试自己做了做 没做出来,看了别人博客的分析之后发现自己连 d= -b[i]/a[i]都推错了。 kx(大佬)告诉我这题用map存。 于是补了之后交一发,WA5,原因是没有考虑a[i]和b[i]等于0 的时候(这里注意如果a[i]和b[i]都等于0,那么无论d为什么数,都可以) 。 把这部分搞了一下之后再交一,WA37,这次的原因是精度问题 10000000 99999999和 99999999 99999998 的值是一样的,于是推翻了用double的做法。。 最终的结果是把 a[i]和b[i] 都除以公因数,再用pair 存入map数组。
#include<iostream>
#include<cstdio>
#include <cctype>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
#define mem(a,x) memset(a,x,sizeof(a))
#define se second
#define fi first
typedef pair<int,int> pii;
const ll mod=;
const int INF= 0x3f3f3f3f;
const int N=2e5+; int n;
int a[N];
int b[N];
map<pair<int,int> , int> num; priority_queue<int>q; int main()
{
cin>>n;
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=n;i++)
scanf("%d",&b[i]); int maxn=;
int cnt=;
for(int i=;i<=n;i++)
{
if(a[i]==)
{
if(b[i]==) cnt++;
}
else if(b[i]==)
{
num[ pair<int,int>(,) ]++;
maxn=max(maxn,num[ pair<int,int>(,) ] );
}
else
{
// int c= ,因为实在太长了。。
int c= ++num [ pair<int,int>(a[i]/__gcd(a[i],b[i]) , b[i]/__gcd(a[i],b[i]) )];
maxn=max(maxn,c);
} }
cout<<maxn+cnt<<endl; }
D. Zero Quantity Maximization ( Codeforces Round #544 (Div. 3) )的更多相关文章
- 【CodeForces】841D. Leha and another game about graph(Codeforces Round #429 (Div. 2))
[题意]给定n个点和m条无向边(有重边无自环),每个点有权值di=-1,0,1,要求仅保留一些边使得所有点i满足:di=-1或degree%2=di,输出任意方案. [算法]数学+搜索 [题解] 最关 ...
- B. Ohana Cleans Up(Codeforces Round #309 (Div. 2))
B. Ohana Cleans Up Ohana Matsumae is trying to clean a room, which is divided up into an n by n gr ...
- B. The Number of Products(Codeforces Round #585 (Div. 2))
本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535 ...
- 【CodeForces】841C. Leha and Function(Codeforces Round #429 (Div. 2))
[题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最 ...
- Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)
C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...
- CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))
题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发 问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候 如果对于一条边 ...
- 贪心+构造( Codeforces Round #344 (Div. 2))
题目:Report 题意:有两种操作: 1)t = 1,前r个数字按升序排列: 2)t = 2,前r个数字按降序排列: 求执行m次操作后的排列顺序. #include <iostream&g ...
- A. Kyoya and Photobooks(Codeforces Round #309 (Div. 2))
A. Kyoya and Photobooks Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He ...
- B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- 图片转化base64格式
public function Base64EncodeImage($ImageFile) { // 图片转化base64格式 , 图片需要在本地,有访问权限 , 相对于项目路径 if(file_ex ...
- 硬盘分区及Linux文件系统
1. 硬盘物理结构 硬盘物理上主要分为: 盘片 磁道 扇区 机械臂 磁头 主轴 磁道: 当硬盘盘片旋转时,磁头若固定在一个位置上,则磁头会在盘片表面划出一个圆形轨迹,这些圆形轨迹就叫做磁道.以盘片中心 ...
- VSCode安装MathJax插件
曾经我一直照网上的教程安装了半天都没有安装好,直到我找到了一个叫"Markdown+Math"的插件,安装好之后就可以用了.
- 使用vue搭建应用四引入axios
Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中 特性 从浏览器中创建 XMLHttpRequests 从 node.js 创建 http 请求 支持 P ...
- 域名解析中的cname解析和显性URL跳转和隐性URL跳转三者有什么区别
通俗的来讲,cname解析还是属于dns解析,只是把某个域名解析到另外一个域名对应的某个IP的空间中,所以还需要在服务器端(比如nginx)做域名解析(比如把baidu.com做一个cname解析到i ...
- go上传图片微信服务器<<临时素材
type WxImage struct { Type string `json:"type"` MediaId string `json:"media_id"` ...
- powerful number求积性函数前缀和
算法原理 本文参考了 zzq's blog . \(\text{powerful number}\) 的定义是每个质因子次数都 \(\ge 2\) 的数,有个结论是 \(\ge n\) 的 \(\te ...
- @PropertySouce注解 读取 properties文件
https://www.cnblogs.com/whx7762/p/7885735.html 1.@ProtertySource @PropertySouce是spring3.1开始引入的基于java ...
- 全网独发gensim中similarities.Similarity用法
index = similarities.MatrixSimilarity(lsi[corpus]) # 管网的原文翻译如下: 警告:similarities.MatrixSimilarity类仅仅适 ...
- vue插件(还真是第一次接触)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...