A17 排序 中位数 距离和的最小值

视频链接:51 排序 中位数 距离和的最小值_哔哩哔哩_bilibili

CH0501 货仓选址

 

复制代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N=100100;
int n,a[N];

int main(){
  cin>>n;
  for(int i=0; i<n; i++) cin>>a[i];
  sort(a,a+n);
  
  int ans=0;
  for(int i=0; i<n; i++) ans+=abs(a[i]-a[n/2]);
  cout<<ans;
}
复制代码

 

CF1486B Eastern Exhibition

Luogu CF1486B Eastern Exhibition

 

复制代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N=1010;
int n,a[N],b[N];

int main(){
  int t; cin>>t;
  while(t--){
    cin>>n;
    for(int i=0; i<n; i++) cin>>a[i]>>b[i];
    sort(a,a+n); sort(b,b+n);
    
    int x=a[n/2]-a[(n-1)/2]+1;
    int y=b[n/2]-b[(n-1)/2]+1;
    cout<<1LL*x*y<<'\n';
  }
  return 0;
}
复制代码

 

posted @   董晓  阅读(472)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2022-07-21 C05【模板】FHQ Treap P3369 普通平衡树
点击右上角即可分享
微信分享提示