博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
校赛 选修课网址 1097: Meeting
阅读量:4048 次
发布时间:2019-05-25

本文共 1457 字,大约阅读时间需要 4 分钟。

1097: Meeting
Time Limit: 2 Sec  Memory Limit: 64 MB
Submit: 10  Solved: 7
[Submit][Status][Web Board]
Description
There n peoples, they want to meet for discussing something about NBUT ACM Laboratory, so they need to decide a location where they meeting.
But they are lazy, they want a location where the summary of each one’s moving
distance is least, now you know the n peoples’ position, can you help them to calculate the minimum summary of each one’s moving distance. 
Input
Input starts with an integer T(1 <= T <= 20), denoting the number of test case.
For each test case, first line contains an integer n(1 <= n <= 100000), denoting the number of people.
Next line contains n integers Pi(0 <= Pi <= 109), denoting each one’s position. Note that maybe someone stay at the same place. 
Output
For each test case, print the minimum summary of each one’s moving distance. 
Sample Input
1
5
1 2 3 4 5
Sample Output
6
HINT

You can set the location at 3, so the minmum summary of each one’s moving distance is 6(2+1+0+1+2).

找最短路径  sort一下 相对最大的减去相对最小的  只要重复的线段最小就是答案  最短的一般都是在中间

#include
#include
#include
#include
#include
using namespace std;int main(){ long long n,m,i,k,sum,max,min; int a[100010]; ios::sync_with_stdio(false); cin>>k; while(k--) { sum=0; cin>>n; memset(a,0,sizeof(a)); for(i=0;i
>a[i]; sort(a,a+n); max=n-1; min=0; while(max>=min) { sum+=a[max]-a[min]; max--; min++; } cout<
<

转载地址:http://atfci.baihongyu.com/

你可能感兴趣的文章
几个常用的Javascript字符串处理函数 spilt(),join(),substring()和indexof()
查看>>
javascript传参字符串 与引号的嵌套调用
查看>>
swiper插件的的使用
查看>>
layui插件的使用
查看>>
JS牛客网编译环境的使用
查看>>
9、VUE面经
查看>>
关于进制转换的具体实现代码
查看>>
Golang 数据可视化利器 go-echarts ,实际使用
查看>>
mysql 跨机器查询,使用dblink
查看>>
mysql5.6.34 升级到mysql5.7.32
查看>>
dba 常用查询
查看>>
Oracle 异机恢复
查看>>
Oracle 12C DG 搭建(RAC-RAC/RAC-单机)
查看>>
Truncate 表之恢复
查看>>
Oracle DG failover 后恢复
查看>>
mysql 主从同步配置
查看>>
为什么很多程序员都选择跳槽?
查看>>
mongdb介绍
查看>>
mongdb在java中的应用
查看>>
区块链技术让Yotta企业云盘为行政事业服务助力
查看>>