Live2d Test Env

hiho1514 偶像的条件 lower_bound

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

小Hi的学校正面临着废校的大危机。面对学校的危机,小Hi同学们决定从ABC三个班中各挑出一名同学成为偶像。  

成为偶像团体的条件之一,就是3名团员之间的身高差越小越好。  

已知ABC三个班同学的身高分别是A1..AN, B1..BM 和 C1..CL。请你从中选出3名同学Ai, Bj, Ck使得D=|Ai-Bj|+|Bj-Ck|+|Ck-Ai|最小。

输入

第一行包含3个整数,N, M和L。  

第二行包含N个整数,A1, A2, ... AN。(1 <= Ai <= 100000000)

第三行包含M个整数,B1, B2, ... BM。(1 <= Bi <= 100000000)

第四行包含L个整数,C1, C2, ... CL。(1 <= Ci <= 100000000)

对于30%的数据, 1 <= N, M, L <= 100  

对于60%的数据,1 <= N, M, L <= 1000  

对于100%的数据,1 <= N, M, L <= 100000

输出

输出最小的D。

样例输入
3 3 3  
170 180 190  
195 185 175  
180 160 200
样例输出
          10
暴力的枚举(滑稽脸):
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=100010;
int a[4][maxn];
int ans=1000000000,t1,t2,t3,tmp;
void _do(int x,int y){//x最小,y第二 
    for(int i=1;i<=a[x][0];i++) {
        t1=a[x][i];
        int pos=lower_bound(a[y]+1,a[y]+1+a[y][0],t1)-a[y];    
        t2=a[y][pos];
        pos=lower_bound(a[6-x-y]+1,a[6-x-y]+1+a[6-x-y][0],t2)-a[6-x-y];
        t3=a[6-x-y][pos];    
        if(t1!=0&&t2!=0&&t3!=0) {
            tmp=2*(t3-t1);
            if(tmp<ans) ans=tmp;
        }
    }
}
int main()
{
    int n,m,q,i,j,L;
    scanf("%d%d%d",&n,&m,&L);
    a[1][0]=n;a[2][0]=m;a[3][0]=L;
    for(i=1;i<=n;i++) scanf("%d",&a[1][i]);
    for(i=1;i<=m;i++) scanf("%d",&a[2][i]);
    for(i=1;i<=L;i++) scanf("%d",&a[3][i]);
    sort(a[1]+1,a[1]+1+n);
    sort(a[2]+1,a[2]+1+m);
    sort(a[3]+1,a[3]+1+L);
    _do(1,2);
    _do(1,3);
    _do(2,3);
    _do(2,1);
    _do(3,1);
    _do(3,2);
    printf("%d\n",ans);
}
View Code

 





posted @ 2017-10-23 21:50  nimphy  阅读(177)  评论(0编辑  收藏  举报