csu 1947 三分
题意:
长者对小明施加了膜法,使得小明每天起床就像马丁的早晨一样。 今天小明早上6点40醒来后发现自己变成了一名高中生,这时马上就要做早操了,小明连忙爬起来 他看到操场密密麻麻的人,突然灵光一闪想到了一个很严肃的问题: 操场上有n个人,第i个人的坐标为(xi, yi),刚开始每个人都站的很松散,现在想把所有人排成一行平行x轴紧挨着的队伍,求所有人需要移动的曼哈顿距离之和的最小值。
分析:
第一次三分高度,第二次,按照x 坐标排序,三分起点。
csuoj 不支持bits/stdc++.h %I64d
#include <cstdio>
#include <algorithm> using namespace std; const int maxn = + ; int n;
struct Point
{
int x,y;
} node[maxn]; bool cmp(Point a,Point b)
{
return a.x<b.x;
} long long calc(int x)
{
long long sum = ;
for(int i=; i<n; i++)
sum += abs(node[i].y-x);
return sum;
} long long calc2(int mid)
{
long long ret=;
for(int i=; i<n; i++)
ret+=abs(node[i].x-mid-i);
return ret;
} int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d",&n))
{
int L = 1e9,R = -1e9;
for(int i=; i<n; i++)
{
scanf("%d%d",&node[i].x,&node[i].y);
L = min(L,node[i].y);
R = max(R,node[i].y);
} sort(node,node+n,cmp); while (L<R-)
{
int lmid=(L+R)>>;
int rmid=(lmid+R)>>;
if (calc(lmid)<=calc(rmid)) R=rmid;
else L=lmid;
} long long ans=min(calc(L),calc(R));
L=node[].x-n-;
R=node[n-].x;
while (L<R-) //三分起始点
{
int lmid=(L+R)>>;
int rmid=(lmid+R)>>;
if (calc2(lmid)<=calc2(rmid)) R=rmid;
else L=lmid;
} ans+=min(calc2(L),calc2(R));
printf("%lld\n",ans);
} return ;
} /**********************************************************************
Problem: 1947
User: CrimsonFantasy
Language: C++
Result: AC
Time:1124 ms
Memory:1900 kb
**********************************************************************/
csu 1947 三分的更多相关文章
- csu 1548(三分)
1548: Design road Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 383 Solved: 200[Submit][Status][We ...
- 三分 --- CSU 1548: Design road
Design road Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548 Mean: 目的:从(0,0)到 ...
- CSU 1548 Design road(三分查找)
题目链接:https://cn.vjudge.net/problem/142542/origin Description You need to design road from (0, 0) to ...
- 关于ACM,关于CSU
原文地址:http://tieba.baidu.com/p/2432943599 前言: 即将进入研二,ACM的事情也渐渐远去,记忆终将模糊,但那段奋斗永远让人热血沸腾.开个贴讲讲ACM与中南的故事, ...
- CSU训练分类
√√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 ...
- hdu3714 三分找最值
Error Curves Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- BZOJ 1857 传送带 (三分套三分)
在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.lxhgww在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R.现在lxhgww想从 ...
- hdu 4717(三分求极值)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 思路:三分时间求极小值. #include <iostream> #include ...
- HDU2438 数学+三分
Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
随机推荐
- 字符型图片验证码,使用tensorflow实现卷积神经网络,进行验证码识别CNN
本项目使用卷积神经网络识别字符型图片验证码,其基于 TensorFlow 框架.它封装了非常通用的校验.训练.验证.识别和调用 API,极大地减低了识别字符型验证码花费的时间和精力. 项目地址: ht ...
- leetcode 862 shorest subarray with sum at least K
https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/ 首先回顾一下求max子数组的值的方法是:记录一个前缀min值, ...
- (转)IPC相关的命令
IPC相关的命令 原文:http://www.cnblogs.com/jjzd/p/6773090.html 进程间通信概述 进程间通信有如下的目的: 1.数据传输,一个进程需要将它的数据发送给另一个 ...
- 案例43-crm练习获取客户列表使用struts2
1 src下配置文件 1 struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYP ...
- php 中全局变量global 的使用
简介 即使开发一个新的大型PHP程序,你也不可避免的要使用到全局数据,因为有些数据是需要用到你的代码的不同部分的.一些常见的全局数据有:程序设定类.数 据库连接类.用户资料等等.有很多方法能够使这些数 ...
- Oracle关于All和Any
简单的说 All等价于N个And语句,Any等价于N个or语句.
- 九度oj题目1511:从尾到头打印链表
题目1511:从尾到头打印链表 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:6010 解决:1805 题目描述: 输入一个链表,从尾到头打印链表每个节点的值. 输入: 每个输入文件仅包 ...
- vim脚本语言
转自:http://man.chinaunix.net/newsoft/vi/doc/usr_41.html#usr_41.txt Vim 脚本语言在很多地方用到,包括 vimrc 文件, 语法文件, ...
- github不支持tlsv1.1后, 出现SSL connect error
过完年回来, github不安分了, 发了博文说不支持TLSv1/TLSv1.1: Weak cryptographic standards removed, 没看到这篇博文之前, 还以为是代理问题, ...
- [转] EF cannot be tracked because another instance of this type with the same key is already being tracked
本文转自:http://stackoverflow.com/questions/6033638/an-object-with-the-same-key-already-exists-in-the-ob ...