the Captain题解;】的更多相关文章

20200216题目题解 这是一篇题解祭题解记,但一共就一道题目.(ROS菜大了) 题目如下: The Captain 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小费用. Input 第一行包含一个正整数n(<=n<=),表示点数. 接下来n行,每行包含两个整数x[i],y[i](<=x[i],y[i]<=^),依次表示每个点的坐标. Output 一个整数,即最小费用. Sample Input…
BZOJ 4152 很显然这个题是让找最短路: 这种通过一个节点到达另一个点的路径我们可以想到dijkstra,然后这道题我们可以看到点是比较多的,所以我们怎么存图呢? 首先我们对于任意三个点,A(x1,y2),B(x2,y2),C(x3,y3)(假设A,B,,C相邻),我们画个图,如果我们直接从A到C那么我们走的将会是x的累和取min y的累和,但如果从a到b再到c我们取得是x的差值,y的差值取min加上b到c的距离,通过计算比较,是比直接到省时间的,推广到四个点也是,但是要保证相邻两个点建图…
https://www.lydsy.com/JudgeOnline/problem.php?id=4152 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小费用. 先以纵坐标从下往上不考虑横坐标为例,发现我们付出代价一定是最近的两行之间的点的代价,于是对y排序,则相邻两个点连边即可. 横坐标同理. #include<map> #include<cmath> #include<stack>…
题面 题解 将所有点根据…
Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 模拟一下就好了 代码 #include<bits/stdc++.h> using namespace std; string s[3]; map<char,int>r,c; char ss[2][107]; int main() { s[0]="qwertyuiop"…
最短路 题解:http://zyfzyf.is-programmer.com/posts/97953.html 按x坐标排序,相邻点之间连边.满足dist(x1,x3)<=dist(x1,x2)+dist(x2,x3)(因为可以走y) 再按y坐标排序,相邻点之间连边.同上 然而SPFA挂了……写了Dijkstra /************************************************************** Problem: 4152 User: Tunix La…
[BZOJ4152]The Captain(最短路) 题面 BZOJ Description 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小费用. Input 第一行包含一个正整数n(2<=n<=200000),表示点数. 接下来n行,每行包含两个整数x[i],yi,依次表示每个点的坐标. Output 一个整数,即最小费用. Sample Input 5 2 2 1 1 4 5 7 1 6 7 Sample…
[BZOJ4152][AMPPZ2014]The Captain Description 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求从1号点走到n号点的最小费用. Input 第一行包含一个正整数n(2<=n<=200000),表示点数. 接下来n行,每行包含两个整数x[i],y[i](0<=x[i],y[i]<=10^9),依次表示每个点的坐标. Output 一个整数,即最小费用. Sample Input 5 2…
C. Captain Marmot time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has n regi…
A. Best Subsegment time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given array a1,a2,…,ana1,a2,…,an. Find the subsegment al,al+1,…,aral,al+1,…,ar (1≤l≤r≤n1≤l≤r≤n) with maximum arith…