时间限制:300 ms 内存限制:64 MB

The distance of triples (三元组) (a,b,c) is defined as D(a,b,c)=∣a−b∣+∣b−c∣+∣c−a∣. Now given three non-empty integer sets S1, S2 and S3, you are supposed to find the minimum distance of all the possible triples (a,b,c) where a∈S1, b∈S2 and c∈S3.

Input Specification:
Each input file contains one test case. For each case, the first line gives three positive integers N1, N2 and N3 (all no more than 104), which are the sizes of S1, S2 and S3, respectively. Then the members of the three sets are given in the following three lines, respectively. All the numbers are integers in the range [−104,104], and they are distinct within each set. The numbers in a line are separated by spaces.

Output Specification:
For each case, print in a line MinD(a, b, c) = d, where (a, b, c) are the triples that has the minimum distance, and d is the corresponding distance. If the solution is not unique, output the largest triples.

Sample Input:
4 4 6
0 9 -1 11
10 -25 11 -10
9 2 41 17 12 30
Sample Output:
MinD(11, 11, 12) = 2
Hint:
Notice that there are two solutions. The other one is MinD(9, 10, 9) = 2. Since (11, 11, 12) is larger, this one must be printed out.

这是一道408真题,可能比较典型吧,看了题解以后发现没有比较清楚的,直接用的王道书上的思想写了一遍

#include<bits/stdc++.h>
using namespace std;
struct node {int aa;int bb;int cc;
};
vector<int> a,b,c;
int find_min(int a,int b,int c) {if (a <= b && a <= c) {return true;} else {return false;}
}
int la,lb,lc;
vector<vector<int>> ans;
int main(void) {freopen("pataTrain//in.txt","r",stdin);cin>>la>>lb>>lc;for(int i = 0;i < la;i++) {int num;cin>>num;a.push_back(num);}for(int i = 0;i < lb;i++) {int num;cin>>num;b.push_back(num);}for(int i = 0;i < lc;i++) {int num;cin>>num;c.push_back(num);}int dis = 0;int mindis = INT_MAX;;int pa,pb,pc;sort(a.begin(),a.end());sort(b.begin(),b.end());sort(c.begin(),c.end());for(pa = 0,pb = 0,pc = 0;pa < la && pb < lb && pc < lc; ) {int na = a[pa],nb = b[pb],nc = c[pc];dis = abs(na - nb) + abs(nb - nc) + abs(nc - na);if (dis < mindis) {mindis = dis;ans.clear();ans.push_back({na,nb,nc});} else if(dis == mindis) {ans.clear();ans.push_back({na,nb,nc});}if (find_min(na,nb,nc)) {pa++; } else if(find_min(nb,na,nc)) {pb++;} else {pc++;}}printf("MinD(%d, %d, %d) = %d",ans[0][0],ans[0][1],ans[0][2],mindis);return 0;
}

浙江大学软件学院2020年保研真题Distance of Triples (25 分)相关推荐

  1. 浙江大学软件学院2020年保研上机模拟练习 7-4 Shopping With Coupons

    目录 解题思路演进过程 第一次程序 第二次程序 第三次程序 解题思路演进过程 首先是题目的理解上:有n个商品,n张优惠券,实际上能买的商品个数最多就是n*n,为啥呢,这题默认是买一个商品必须用一张券, ...

  2. 浙江大学软件学院2020年保研上机模拟练习

    浙江大学软件学院2020年保研上机模拟练习 7-1.Standard Form of Polynomial (20分) 7-2.Distance of Triples (25分) 7-3. Parti ...

  3. 浙江大学软件学院2020年保研上机真题练习

    用浏览器打开html文件即可,需要源文件私聊

  4. 浙江大学软件学院2020年保研上机模拟练习 7-2 Distance of Triples

    思路一: 3个数组都按照小到大排序,设置3个指针,起始都在数组的末尾,如果1个指针向前移动1位可以让对应元素和另两个数组元素的距离之和减小,则移动它.如果某一回合三个指针都没动,就跳出循环. 非满分: ...

  5. 浙江大学软件学院2020年保研上机模拟练习 7-3 Partial School Ranking

    并查集的使用时注意: 1. 合并两个结点是 F[sa] = sb 而不是 sb = F[sa],想一下含义. 2. 给每个结点赋予其自身为父节点时,要先判断它的父节点是不是0,也许已经有了. 我把照片 ...

  6. 【PTA】【878真题】浙江大学软件学院878自命题2016真题

    说明: 题目来自PTA平台的C语言与数据结构考研模拟卷(1) 部分题目没答案是因为博主也做错了,不知道正确答案 如果有不会做的题目或者知道正确答案,可以评论或者私信我,谢谢 选择题 2-1 若有以下说 ...

  7. 浙江大学计算机推免保研,浙江大学计算机科学与技术学院数字化艺术与设计保研细则...

    浙江大学计算机科学与技术学院数字化艺术与设计保研细则信息,是考研之前需要获取相应的考研信息,比如考试大纲.招考专业.招考目录等等基本信息,这些内容是进行考研前期工作的必要准备.考生可以从各院校的研招网 ...

  8. 浙江大学计算机学院保研率,浙江大学2020届保研率25.9%,主要保研本校、复旦、交大、北大...

    原标题:浙江大学2020届保研率25.9%,主要保研本校.复旦.交大.北大 推免大户是医学院.计算机.电工.信息学院等. 1.推免比例 根据浙江大学本科生院<浙江大学推荐2020年免试研究生公示 ...

  9. 浙江大学计算机与软件学院2019年保研上机模拟练习 --- 凌宸1642

    浙江大学计算机与软件学院2019年保研上机模拟练习 - 凌宸1642 7-1 Happy Numbers (20 分) - 简单数学 A happy number is defined by the ...

最新文章

  1. 华为交换机路由器常用命令
  2. 谁来担责!无人驾驶汽车还需要汽车保险吗?
  3. R:matlab交互,数据调用
  4. python数字判断规则_判断Python输入是否为数字、字符(包括正则表达式)-阿里云开发者社区...
  5. PHP中的stdClass 【转】
  6. java使用monkeyrunner_MonkeyRunner 实践----用 java 来编写脚本
  7. 【Flink】Flink TaskManager 一直 User file cache uses directory
  8. 重磅!华为方舟编译器招募 2000 程序员!
  9. Visual Studio 2019报错:缺少mfc120.dll
  10. 关于工作[update]
  11. html中的form是空标签么,关于html 中form表单的内标签和使用
  12. SCCM配置PXE启动
  13. 电脑同时打开多个软件如何设置
  14. 二、自然语言处理发展历程
  15. 每一代内存的读写速度大概是多少?
  16. 在浏览器中输入URL(如www.baidu.com)到显示页面经历哪些过程,涉及到哪些协议?
  17. DayDayUp:2019.01.24新东方年会—俞敏洪点赞并奖励吐槽神曲《释放自我》12万元!—附全歌词(牛逼的人在哪里都不会彷徨)
  18. c/c++: window下安装mingw-w64
  19. css textarea行数_超级简单:在一个TextArea中如何限制行数和字符数-阿里云开发者社区...
  20. 第三节 树莓派EC20之PPP拨号上网

热门文章

  1. 【CloudShell】阿里云壳EDR卸载指南
  2. 从Anker到SHEIN,对不起我要放弃Amazon了
  3. 亚麻/苹果/脸书/谷歌/微软面试图鉴
  4. mvcnn代码详解_使用colab运行tensorflow版本的faster-rcnn
  5. 一文读懂 Java 反射机制那些事
  6. 计算机公司客户电话怎么打,企业微信公费电话怎么打多人通话【方法】
  7. 使用 Dva 开发复杂 SPA
  8. JVM和DVM的区别
  9. 计算机运算器的功能,计算机中运算器的主要功能
  10. K8S学习之Statefulset