51nod1110(xjb)
2024-08-25 17:03:27
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1110
题意:中文题诶~
思路:可以将在 xi 位置,权值为 wi 的点看作有 wi 个点在 xi 位置.然后再按位置排一下序,再找中位数即可;
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#define ll long long
using namespace std; const int MAXN = 1e4+;
pair<ll, ll> p[MAXN]; int main(void){
int n;
ll ans=, sum=;
scanf("%d", &n);
for(int i=; i<n; i++){
scanf("%lld%lld", &p[i].first, &p[i].second);
ans+=p[i].second;
}
ans>>=;
sort(p, p+n);
ll cnt=;
int indx=-;
while(){
cnt += p[++indx].second;
if(cnt >= ans) break;
}
for(int i=; i<n; i++){
if(i == indx) continue;
sum += abs(p[indx].first-p[i].first)*p[i].second;
}
printf("%lld\n", sum);
return ;
}
最新文章
- 1Z0-053 争议题目解析419
- xshell4|5远程连接工具
- 转:Teach Yourself Programming in Ten Years——用十年教会自己编程
- 使用命令行工具将Android应用转换成BlackBerry PlayBook应用
- VC6.0代码移植到VS2008运行时乱码问题解决
- Jsp与servlet之间页面跳转及参数传递实例(转)
- eclipse连接远程hadoop集群开发时0700问题解决方案
- [转]windows10 64位环境下安装mysql5.7.17
- _tcscat在Debug和Release根据问题
- Ceph Object Gateway Admin api 获取用户列表问题
- windows下搭建virtualenv虚拟环境
- 2017 清北济南考前刷题Day 4 afternoon
- static 变量(静态变量)
- Nginx的内部(进程)模型
- mysql锁机制详解
- 认识LDAP协议
- [Linux]systemd和sysV
- canvas实现五子棋界面
- IO知识点整理(文件File类的使用)
- 00-02.PHP 网站假设 之 学习PHP语法 [James建站]