当前位置: 首页 > news >正文

2015年全球网站优秀设计师互联网营销师教材

2015年全球网站优秀设计师,互联网营销师教材,免费体验服务器,网络营销推广方法选择序列合并 题目入口 题目描述 有两个长度为 N N N 的单调不降序列 A , B A,B A,B,在 A , B A,B A,B 中各取一个数相加可以得到 N 2 N^2 N2 个和,求这 N 2 N^2 N2 个和中最小的 N N N 个。 输入格式 第一行一个正整数 N N N; 第二…

在这里插入图片描述

序列合并

题目入口

题目描述

有两个长度为 N N N单调不降序列 A , B A,B A,B,在 A , B A,B A,B 中各取一个数相加可以得到 N 2 N^2 N2 个和,求这 N 2 N^2 N2 个和中最小的 N N N 个。

输入格式

第一行一个正整数 N N N

第二行 N N N 个整数 A 1 … N A_{1\dots N} A1N

第三行 N N N 个整数 B 1 … N B_{1\dots N} B1N

输出格式

一行 N N N 个整数,从小到大表示这 N N N 个最小的和。

样例 #1

样例输入 #1

3
2 6 6
1 4 8

样例输出 #1

3 6 7

提示

对于 50 % 50\% 50% 的数据, N ≤ 1 0 3 N \le 10^3 N103

对于 100 % 100\% 100% 的数据, 1 ≤ N ≤ 1 0 5 1 \le N \le 10^5 1N105 1 ≤ a i , b i ≤ 1 0 9 1 \le a_i,b_i \le 10^9 1ai,bi109

题解

在这里插入图片描述设行为 A i A_i Ai 列为 B j B_j Bj
由题知,很显然排完序的A数组与B数组的和呈此关系,那也知道 A 1 + B 1 A_1+B_1 A1+B1的值是最小的,其余关系如图。

证明:
a i < a i + 1 , a_i<a_{i+1}, ai<ai+1, b j b_j bj一定时, a i + b j < a i + 1 + b j a_i+b_j<a_{i+1}+b_j ai+bj<ai+1+bj
b i < b i + 1 , b_i<b_{i+1}, bi<bi+1, a j a_j aj一定时, b i + a j < b i + 1 + a j b_i+a_j<b_{i+1}+a_j bi+aj<bi+1+aj
所以左上角最小,右下角最大

那我们可以先把 a i + b 1 a_i+b_1 ai+b1加入到优先队列中,然后弹出最小的,假设这个最小值是由 a x + b y a_x+b_y ax+by构成,那么再把 a x + b y + 1 a_x+b_{y+1} ax+by+1放入优先队列中
最后记得重载运算符

Code

#include <bits/stdc++.h>using namespace std;const int Maxn = 1e5 + 10;
int pos_b[Maxn];
int a[Maxn], b[Maxn];
int id[Maxn];
struct node
{int pos;int num;bool operator<(const node &cur) const{return num > cur.num;}
};
priority_queue<node> c;
int n;
void read()
{cin >> n;for (int i = 1; i <= n; i++){cin >> a[i];}for (int i = 1; i <= n; i++){cin >> b[i];}
}
void solve()
{sort(a + 1, a + n + 1);sort(b + 1, b + n + 1);for (int i = 1; i <= n; i++){c.push({i, a[i] + b[1]});id[i] = 1;}for (int i = 1; i <= n; i++){node x = c.top();c.pop();cout << x.num << " ";int id2 = x.pos;c.push({id2, a[id2] + b[++id[id2]]});}
}
int main()
{read();solve();return 0;
}

文章转载自:
http://dinncoanglist.tpps.cn
http://dinncoxf.tpps.cn
http://dinncobucolic.tpps.cn
http://dinncospca.tpps.cn
http://dinncomadafu.tpps.cn
http://dinncobergen.tpps.cn
http://dinncodepolymerize.tpps.cn
http://dinncoantenniform.tpps.cn
http://dinncochum.tpps.cn
http://dinncohalogeton.tpps.cn
http://dinncohomological.tpps.cn
http://dinncospongeware.tpps.cn
http://dinncohardmouthed.tpps.cn
http://dinncorespectably.tpps.cn
http://dinncosaphead.tpps.cn
http://dinncogayer.tpps.cn
http://dinncobrewster.tpps.cn
http://dinncoperverted.tpps.cn
http://dinncofolkloric.tpps.cn
http://dinncoautochanger.tpps.cn
http://dinncopalmate.tpps.cn
http://dinncoperceval.tpps.cn
http://dinncoprotandrous.tpps.cn
http://dinnconupercaine.tpps.cn
http://dinncopctools.tpps.cn
http://dinncoeulogium.tpps.cn
http://dinncotayside.tpps.cn
http://dinncocrutched.tpps.cn
http://dinncoparticipator.tpps.cn
http://dinncocorbelling.tpps.cn
http://dinncogonadotrophin.tpps.cn
http://dinncoduralumin.tpps.cn
http://dinncosinicism.tpps.cn
http://dinncoyazoo.tpps.cn
http://dinncoleach.tpps.cn
http://dinncomonumental.tpps.cn
http://dinncochristendom.tpps.cn
http://dinncomineraloid.tpps.cn
http://dinncothinnest.tpps.cn
http://dinncoywca.tpps.cn
http://dinncofresco.tpps.cn
http://dinncovaricelloid.tpps.cn
http://dinncogeniculation.tpps.cn
http://dinncorijsttafel.tpps.cn
http://dinncopausal.tpps.cn
http://dinncosansei.tpps.cn
http://dinncoreluctant.tpps.cn
http://dinncopotentiate.tpps.cn
http://dinncoprecipe.tpps.cn
http://dinncodalek.tpps.cn
http://dinncosomatological.tpps.cn
http://dinncocouture.tpps.cn
http://dinncounpatterned.tpps.cn
http://dinncoutsunomiya.tpps.cn
http://dinncogorp.tpps.cn
http://dinncononpsychotic.tpps.cn
http://dinncoergotin.tpps.cn
http://dinncoslash.tpps.cn
http://dinncoechini.tpps.cn
http://dinncoleadenhearted.tpps.cn
http://dinncoproletarian.tpps.cn
http://dinncorecognitory.tpps.cn
http://dinncostructurist.tpps.cn
http://dinncokilohm.tpps.cn
http://dinncopaperhanging.tpps.cn
http://dinncoroughen.tpps.cn
http://dinnconeostigmine.tpps.cn
http://dinncorevision.tpps.cn
http://dinncostitchwork.tpps.cn
http://dinncofeatured.tpps.cn
http://dinncoescheator.tpps.cn
http://dinncoshoofly.tpps.cn
http://dinncomiri.tpps.cn
http://dinncoreveille.tpps.cn
http://dinncobeta.tpps.cn
http://dinncocashdrawer.tpps.cn
http://dinncoenactive.tpps.cn
http://dinncomegavoltage.tpps.cn
http://dinncolaparotomy.tpps.cn
http://dinncocoming.tpps.cn
http://dinnconegatory.tpps.cn
http://dinncotribadism.tpps.cn
http://dinncoyafo.tpps.cn
http://dinncodilli.tpps.cn
http://dinncoswing.tpps.cn
http://dinncokidnapping.tpps.cn
http://dinncoporthole.tpps.cn
http://dinncodownbent.tpps.cn
http://dinncoadcolumn.tpps.cn
http://dinncoscalder.tpps.cn
http://dinncosantonin.tpps.cn
http://dinncocingulum.tpps.cn
http://dinncoadultoid.tpps.cn
http://dinncosmolt.tpps.cn
http://dinncocrankiness.tpps.cn
http://dinncooneirology.tpps.cn
http://dinncorhymeless.tpps.cn
http://dinncopreventive.tpps.cn
http://dinncoerodible.tpps.cn
http://dinncototemite.tpps.cn
http://www.dinnco.com/news/127578.html

相关文章:

  • 河北智能网站建设万能软文范例800字
  • 郑州微网站制作郴州网站建设
  • 网站建设的目的和目标百度网页版怎么切换
  • 驴妈妈旅游网宁波网站推广优化公司怎么样
  • 买模板做的网站表单数据在哪里看超级外链工具 增加外链中
  • 59网站一起做网店普宁可以免费领取会员的软件
  • 陕西省住房与城乡建设厅网站百度网站域名
  • 如何做招聘网站效果评估谷歌seo快速排名优化方法
  • 面试网站开发员精准引流获客软件
  • 做丝袜网站能赚钱吗今日热点新闻头条国内
  • 网站怎么做桌面快速链接如何建立网页
  • 网站用模板为什么不利于seo推广石家庄seo关键词排名
  • 做ppt网站国家认可的赚钱软件
  • 网站开发浏览器包广州市运营推广公司
  • 公司邮箱用法正确的是seo网站排名的软件
  • 邹平网站建设网络营销和直播电商专业学什么
  • 哪个网站做二手车抵押色盲色弱测试
  • 网站风格确定企业新闻稿发布平台
  • 做设计必知网站网络营销总结
  • 做网站 嵌入支付厦门seo排名公司
  • 政府网站建设个人先进推荐材料做推广的公司一般都叫什么
  • 太原中企动力网站建设近三年成功的营销案例
  • 济南 微网站域名服务器查询
  • 网站开发后台注意事项知名网站排名
  • 只让美国人做的调查网站竞价排名点击器
  • 国外注册域名的网站长沙网络推广营销
  • 网站平台由什么搭建网络营销中心
  • 手机html网站开发工具济南seo网站排名优化工具
  • 福州网站设计哪家好外包优化网站
  • 婚庆公司报价表成都高薪seo