Codeforces Round #635 (Div. 2) D-Xenia and Colorful Gems 二分
Posted qingyuyyyyy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #635 (Div. 2) D-Xenia and Colorful Gems 二分相关的知识,希望对你有一定的参考价值。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 2e5+10;
typedef long long ll;
ll t, n1, n2, n3;
ll a[N], b[N], c[N];
//分别固定一个数 设为a[i]
//然后从 b 和 c 中找一个小于等于他的 和 一个大于等于他的
//然后枚举每个数字的每个数
ll solve(ll a[], ll n1, ll b[], ll n2, ll c[] , ll n3)
{
ll ans = 2e18, x, y, z;
for(int i = 1; i <= n1; i++)
{
x = a[i];
int l = 1, r = n2;
while(l < r)
{
int mid = l + r >>1;
if(b[mid] >= x)
r = mid;
else
l = mid +1;
}
if(b[l] >= x)
y=b[l];
else
continue;
l = 1, r = n3;
while(l < r)
{
int mid = l + r + 1 >>1;
if(c[mid] <= x)
l = mid;
else
r = mid - 1;
}
if(c[l] <= x)
z = c[l];
else
continue;
ans=min(ans, (x - y) * (x - y) +(x - z) * (x - z) + (y - z) * (y - z));
}
return ans;
}
void solve()
{
cin >> n1 >> n2 >> n3;
for(int i = 1; i <= n1; i++)
cin >> a[i];
for(int i = 1; i <= n2; i++)
cin >> b[i];
for(int i = 1; i <= n3; i++)
cin >> c[i];
sort(a + 1, a + 1 + n1);
sort(b + 1, b + 1 + n2);
sort(c + 1, c + 1 + n3);
ll ans = 2e18;
ans = min(ans, solve(a, n1, b, n2, c, n3));
ans = min(ans, solve(a, n1, c, n3, b, n2));
ans = min(ans, solve(b, n2, a, n1, c, n3));
ans = min(ans, solve(b, n2, c, n3, a, n1));
ans = min(ans, solve(c, n3, b, n2, a, n1));
ans = min(ans, solve(c, n3, a, n1, b, n2));
cout << ans << endl;
}
int main()
{
cin >> t;
while(t --)
solve();
return 0;
}
以上是关于Codeforces Round #635 (Div. 2) D-Xenia and Colorful Gems 二分的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #635 (Div. 2)ABCDE(题解)
Codeforces Round #635 (Div. 1)B(二分查找前驱后继)
Codeforces Round #635 (Div. 2) AIchihime and Triangle
Codeforces Round #635 (Div. 2) D-Xenia and Colorful Gems 二分
Codeforces Round #635 (Div. 2) DXenia and Colorful Gems
Codeforces Round #635 (Div. 2) E——Kaavi and Magic Spell 区间dp