传送门

文章目录

  • 题意:
  • 思路:

题意:

给你三个数组a,b,ca,b,ca,b,c,让你从每个数组中选择一个数x,y,zx,y,zx,y,z,使得(x−y)2+(x−z)2+(y−z)2(x-y)^2+(x-z)^2+(y-z)^2(x−y)2+(x−z)2+(y−z)2最小,求这个最小值。

思路:

由于答案一定是x≤y≤zx\le y\le zx≤y≤z的形式(当然这里的x,y,zx,y,zx,y,z与题意的x,y,zx,y,zx,y,z不同),所以我们就可以跑一个3!3!3!排列,让他们分别为x,y,zx,y,zx,y,z,让后枚举其中一个二分另外俩就行了。
具体实现可以写个函数就比较方便了。
我这里写的是枚举xxx,让后分两种即找yyy和找zzz,如果找yyy的话,假设现在已经有x≤yx\le yx≤y了,那么找的zzz根据平方的性质,最好是x+(y−x)/2x+(y-x)/2x+(y−x)/2附近的位置,二分找即可,对于zzz同理。
总结:这个题瞎搞都能过。

// Problem: D. Xenia and Colorful Gems
// Contest: Codeforces - Codeforces Round #635 (Div. 2)
// URL: https://codeforces.com/contest/1337/problem/D
// Memory Limit: 256 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const LL inf=0x3f3f3f3f3f3f3f3f;
const double eps=1e-6;int n1,n2,n3;
LL a[N],b[N],c[N];LL get(int i,int j,int k) {//cout<<i<<' '<<j<<' '<<k<<endl;return (a[i]-b[j])*(a[i]-b[j])+(a[i]-c[k])*(a[i]-c[k])+(b[j]-c[k])*(b[j]-c[k]);
}LL solve() {LL ans=inf;for(int i=1;i<=n1;i++) {int val1=a[i];int pos1=lower_bound(b+1,b+1+n2,val1)-b;if(pos1<=n2) {int pos2=lower_bound(c+1,c+1+n3,a[i]+(b[pos1]-a[i])/2)-c;if(pos2<=n3) ans=min(ans,get(i,pos1,pos2));         pos2--;if(pos2>=1) ans=min(ans,get(i,pos1,pos2));}pos1++;if(pos1<=n2) {int pos2=lower_bound(c+1,c+1+n3,a[i]+(b[pos1]-a[i])/2)-c;if(pos2<=n3) ans=min(ans,get(i,pos1,pos2));            pos2--;if(pos2>=1) ans=min(ans,get(i,pos1,pos2));}pos1-=2;if(pos1>=1) {int pos2=lower_bound(c+1,c+1+n3,b[pos1]+(a[i]-b[pos1])/2)-c;if(pos2<=n3) ans=min(ans,get(i,pos1,pos2));          pos2--;if(pos2>=1) ans=min(ans,get(i,pos1,pos2));}pos1=lower_bound(c+1,c+1+n3,val1)-c;if(pos1<=n3) {int pos2=lower_bound(b+1,b+1+n2,a[i]+(c[pos1]-a[i])/2)-b;if(pos2<=n2) ans=min(ans,get(i,pos2,pos1));         pos2--;if(pos2>=1) ans=min(ans,get(i,pos2,pos1));}pos1++;if(pos1<=n3) {int pos2=lower_bound(b+1,b+1+n2,a[i]+(c[pos1]-a[i])/2)-b;if(pos2<=n2) ans=min(ans,get(i,pos2,pos1));            pos2--;if(pos2>=1) ans=min(ans,get(i,pos2,pos1));}pos1-=2;//cout<<pos1<<' '<<c[pos1]<<' '<<a[i]<<endl;if(pos1>=1) {int pos2=lower_bound(b+1,b+1+n2,c[pos1]+(a[i]-c[pos1])/2)-b;if(pos2<=n2) ans=min(ans,get(i,pos2,pos1));          pos2--;if(pos2>=1) ans=min(ans,get(i,pos2,pos1));}}return ans;
}int main()
{//  ios::sync_with_stdio(false);
//  cin.tie(0);int _; scanf("%d",&_);while(_--) {scanf("%d%d%d",&n1,&n2,&n3);for(int i=1;i<=n1;i++) scanf("%lld",&a[i]);for(int i=1;i<=n2;i++) scanf("%lld",&b[i]);for(int i=1;i<=n3;i++) scanf("%lld",&c[i]);sort(a+1,a+1+n1); sort(b+1,b+1+n2); sort(c+1,c+1+n3);n1=unique(a+1,a+1+n1)-a-1;n2=unique(b+1,b+1+n2)-b-1;n3=unique(c+1,c+1+n3)-c-1;printf("%lld\n",solve());}return 0;
}
/**/

Codeforces Round #635 (Div. 2) D. Xenia and Colorful Gems 暴力 + 二分相关推荐

  1. Codeforces Round #635 (Div. 2) D.Xenia and Colorful Gems

    Codeforces Round #635 (Div. 2) D.Xenia and Colorful Gems 题目链接 Xenia is a girl being born a noble. Du ...

  2. Codeforces Round #593 (Div. 2) D. Alice and the Doll 暴力 + 二分

    传送门 文章目录 题意: 思路: 题意: 思路: 还以为这个题有什么高深的算法,结果就是个暴力. 由于n∗mn*mn∗m达到了1e101e101e10的级别,所以直接暴力肯定是不行的,考虑有很多空格, ...

  3. Codeforces Round #635 (Div. 1) C. Kaavi and Magic Spell 区间dp

    传送门 文章目录 题意: 思路: 题意: 给你两个串s,ts,ts,t,每次都可以从sss的开头拿一个字符放到AAA串的开头或结尾,问最终有多少种方案使得ttt是AAA的前缀,注意sss不必全部拿完. ...

  4. Codeforces Round #635 (Div. 2)(A~D)题解

    Codeforces #635 A~D A.Ichihime and Triangle B.Kana and Dragon Quest game C.Linova and Kingdom D.Xeni ...

  5. Codeforces Round #723 (Div. 2) D. Kill Anton 线段树 + 暴力

    传送门 文章目录 题意: 思路: 题意: 给你一个只有ANTOANTOANTO四个字母的字符串,你每次可以交换相邻两个,花费为111,让后让你打乱字符串,使得将打乱的字符串还原为原来的字符串的花费最小 ...

  6. Codeforces Round #207 (Div. 1) B. Xenia and Hamming(gcd的运用)

    题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CO ...

  7. Codeforces Round #197 (Div. 2): C. Xenia and Weights(记忆化搜索)

    题意: 先输入一个长度为10的01串,第i个数字为1表示你有重量为i的砝码无数个,第i个数字为0表示你没有重量为i的砝码,你需要按照以下规则在一个一开始平衡的天平上放上m个砝码 第1个砝码放在天平左边 ...

  8. Codeforces Round #197 (Div. 2): D. Xenia and Bit Operations(线段树)

    题意:定义一个长度2^n的序列{a1, a2-an},序列相邻两个元素或运算之后再进行异或运算再进行或运算(两种运算交替进行)直到只剩下一个数字,这个数字即为序列的值,输入第一行两个数n,m表示序列的 ...

  9. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

最新文章

  1. 重磅!谷歌面试官亲自分享:Google面试技巧
  2. boost::hana::to用法的测试程序
  3. servlet设置cookie实验
  4. Java集合(3)--Iterator迭代器
  5. C语言学习及应用笔记之六:C语言extern关键字及其使用
  6. 百度积极回应阿波龙项目不实报道;半数开发者认为学习新语言很困难;腾讯在长沙建立首个智慧产业总部……...
  7. 记一次阿里面试题:都有哪些进程间通信方式?麻烦你不要再背了
  8. 【读书笔记】-串指令备注
  9. git remote prune,git prune,git fetch --prune等有什么区别
  10. Linux DHCP服务详解
  11. 【C语言开源项目】盘点 GitHub 上不错的 4 个C语言项目
  12. 雷达信号处理基础 ch1 note1
  13. scrapy爬取京东所有图书
  14. 服务器pcb维修方法,电路板维修的方法与口诀
  15. 关于高德地图标注的那些坑
  16. java pkcs8格式的私钥_RSA加密解密中pkcs1与pkcs8格式私钥互相转换
  17. 济南公积金 销户 提取
  18. Android虚拟机是以哪种方式实现的,底层逻辑又是怎样的?
  19. 百年老店焕发青春 中华医学会杂志社漫步云端
  20. 拉线位移编码器零线有电的原因

热门文章

  1. css 字体加粗_HTML基础属性与CSS基础
  2. 她13岁自己造飞机,17岁进麻省理工,3篇黑洞论文被霍金引用......
  3. 被清华免试录取的围棋天才,横扫60位围棋大师的最强AI,竟然都输给了高中生!?...
  4. 史上首次!世界杯使用视频裁判
  5. 一文读懂 KMP 算法
  6. shell查找命令大全
  7. python的所有库_Python 常用库
  8. 微型计算机原理中LEA,微型计算机系统原理及应用(第2版)第2章
  9. oracle crontab e,Linux运维知识之通过crontab -e编辑生成的定时任务,写在哪个文件中...
  10. vim 寄存器 操作_vim指令