zoukankan      html  css  js  c++  java
  • Hdu 2083 简易版之最短距离

    反证法证明得到 中点 满足题意

    #include<cstdio>
    #include<cstdlib>
    #include<iostream>
    #include<map>
    #include<memory.h>
    #include<algorithm>
    using namespace std;
    int a[600];
    int ans;
    int main(){
    	int T,n,i,j;
    	cin>>T;
    	while(T--){
    		ans=0;
    		scanf("%d",&n);
    		for(i=1;i<=n;i++) scanf("%d",&a[i]);
    		sort(a+1,a+n+1);
    		int pos=(n+1)/2;
    		for(i=1;i<=n;i++)
    		  ans+=abs(a[i]-a[pos]);
    		printf("%d
    ",ans);
    	}
    	return 0;
    }

    It is your time to fight!
  • 相关阅读:
    vpp编写plugin
    vrf 命令
    vxlan + 多个vrf
    dpdk helloworld
    Go函数高级
    Go_defer
    Go递归函数
    Go作用域
    Go函数
    Go字符串
  • 原文地址:https://www.cnblogs.com/hua-dong/p/7603912.html
Copyright © 2011-2022 走看看