【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. ...
随机推荐
- PhpStorm 本地管理提交码云和GitHub代码仓库
参考地址:https://www.yflad.cn/1766.html 1:下载Git客户端 2:打开PhpStorm,设置,Version Control → Git.配置git执行文件的路径.gi ...
- 13Oracle Database 存储过程
Oracle Database 存储过程 触发器相当于java中的事件监听,当某事件发生时激活特定的事件并执行相应的逻辑 DML触发器中包含了三种事件 insert update delete 语法格 ...
- eclipse自动换行
Eclipse是一款非常优秀的IDE,但是不能自动换行,需要安装一个插件完成这个功能. 安装办法有两种: 1.在线安装. 选择help-->install new software,点击Add, ...
- 51NOD 1277 字符串中的最大值(KMP)
>>点击进入原题测试<< 思路:用KMP优化的暴力写了一遍,超时!没有充分利用KMP中next数组的性质. 首先这个题是肯定要用到KMP算法的,然后会有一个next[]数组. ...
- spring与quartz整合实现分布式动态创建,删除,改变执行时间定时任务(mysql数据库)
背景:因为在项目中用到了定时任务,当时想到了spring的quartz,写完发现费了很大功夫,光是整合就花了一上午,其中最大的问题就是版本问题,项目中用的是spring3.2.8的版本,查阅发现,3. ...
- 【Codeforces 339C】Xenia and Weights
[链接] 我是链接,点我呀:) [题意] 在天平上放砝码 你要在左边放一下然后到右边放一下 一直重复这样放m次 每次你放在其中一边都要让另外一边的重量比你少 你可以用1~10中的某些砝码 问你要怎样放 ...
- 20170613NOIP模拟赛
共3道题目,时间3小时 题目非原创,仅限校内交流使用 题目名称 Graph Incr Permutation 文件名 graph incr permutation 输入文件 graph.in incr ...
- 作DJANGO ORM时的一些最佳实践
还是国外的正规,都在作DJANGO ORM的解藕化工作了. 外键不用,多对多,一对多,不用. 参考URL: http://scottlobdell.me/2015/01/sql-database-be ...
- Choose and divide
The binomial coefficient C(m, n) is defined as C(m, n) = m! (m − n)! n! Given four natural numbers p ...
- Bellman_ford 算法 Currency Exchange POJ1860
Bellman_ford算法用于寻找正环或者负环! 算法导论: 24.1 The Bellman-Ford algorithm The Bellman-Ford algorithm solves th ...