题目链接: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 ;
}

最新文章

  1. 1Z0-053 争议题目解析419
  2. xshell4|5远程连接工具
  3. 转:Teach Yourself Programming in Ten Years——用十年教会自己编程
  4. 使用命令行工具将Android应用转换成BlackBerry PlayBook应用
  5. VC6.0代码移植到VS2008运行时乱码问题解决
  6. Jsp与servlet之间页面跳转及参数传递实例(转)
  7. eclipse连接远程hadoop集群开发时0700问题解决方案
  8. [转]windows10 64位环境下安装mysql5.7.17
  9. _tcscat在Debug和Release根据问题
  10. Ceph Object Gateway Admin api 获取用户列表问题
  11. windows下搭建virtualenv虚拟环境
  12. 2017 清北济南考前刷题Day 4 afternoon
  13. static 变量(静态变量)
  14. Nginx的内部(进程)模型
  15. mysql锁机制详解
  16. 认识LDAP协议
  17. [Linux]systemd和sysV
  18. canvas实现五子棋界面
  19. IO知识点整理(文件File类的使用)
  20. 00-02.PHP 网站假设 之 学习PHP语法 [James建站]

热门文章

  1. opencv操作相机相关函数
  2. EASYARM-IMX283 烧写uboot和linux系统
  3. SQL Server 2008R2 代理服务-开启
  4. cmake编译成功之后VS2015可以build Solution但是不可以运行的解决办法
  5. 使用jedisPool管理jedis,使用jedis操作redis
  6. HTml js 生成图片
  7. Java如何创建内部类对象
  8. Python: scikit-image 图像的基本操作
  9. NO0:重新拾起C语言
  10. CF785CAnton and Permutation(分块 动态逆序对)