【POJ 1723】 SOLDIERS
【题目链接】
http://poj.org/problem?id=1723
【算法】
中位数
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 10010 struct Pos
{
int x,y;
} a[MAXN]; int i,ans,n; inline bool cmpx(Pos a,Pos b)
{
return a.x < b.x;
}
inline bool cmpy(Pos a,Pos b)
{
return a.y < b.y;
} int main()
{ scanf("%d",&n);
for (i = ; i <= n; i++) scanf("%d%d",&a[i].x,&a[i].y);
sort(a+,a+n+,cmpx);
for (i = ; i <= n; i++) a[i].x = a[i].x - i + ;
sort(a+,a+n+,cmpy);
for (i = ; i <= n; i++) ans += abs(a[i].y - a[(n+)>>].y);
sort(a+,a+n+,cmpx);
for (i = ; i <= n; i++) ans += abs(a[i].x - a[(n+)>>].x);
printf("%d\n",ans); return ; }
【POJ 1723】 SOLDIERS的更多相关文章
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
随机推荐
- 【转载】eclipse设置护眼色详细教程
先上一张效果图: 下面开始设置: 首先设置代码区的背景色: Window–>preference-->General-->Editors-->Test Editors ...
- Linux---shell基本指令
1. 显示当前目录 pwd wangzhengchao@ubuntu:~$ cd /home/wangzhengchao/Desktop/ wangzhengchao@ubuntu:~/Desktop ...
- document.documentElement
1,释意document.documentElement 属性可返回文档的根节点.2,兼容在IE怪异模式下(IE8及以下)无法获取到 HTML标签,用document.body代替: 其余兼容问题参考 ...
- Rsync远程同步工具使用
rsync远程同步工具使用 Rsync(remote synchronize) 是一个远程数据同步工具,可以使用"Rsync算法"同步本地和远程主机之间的文件.Rsync的好处是只 ...
- Linux系统重要的子目录
更多目录知识 http://blog.51cto.com/yangrong/1288072 /etc/fstab 机自动挂载分区/磁盘,规定哪个分区/设备,挂载到哪里 [root@oldboy ~] ...
- python爬虫27 | 当Python遇到MongoDB的时候,存储av女优的数据变得如此顺滑爽~
上次 我们知道了怎么操作 MySQL 数据库 python爬虫26 | 把数据爬取下来之后就存储到你的MySQL数据库. MySQL 有些年头了 开源又成熟又牛逼 所以现在很多企业都在使用 MySQL ...
- angular环境安装与配置
1.安装npm和nodejs,下载地址:https://nodejs.org/en/download/ node -v npm -v 2.配置淘宝代理,下载node_modules npm con ...
- 20180725关于quartz的初识
请参照: https://www.ibm.com/developerworks/cn/opensource/os-cn-quartz/ https://www.w3cschool.cn/quartz_ ...
- 只用html和css画出不等分圆盘,不用canvas
<style> .box{height: 200px;width: 200px;border-radius: 100%; overflow: hidden; margin: 200px; ...
- 怎样编译和安装memcached
怎样编译和安装memcached 编译和安装步骤: $ apt-get install git $ git clone https://github.com/memcached/memcache ...