codeforces 709B B. Checkpoints(水题)
题目链接:
题意:
给了n个点,现在给一个起点,问最少访问n-1个点的最小行走距离是多少;
思路:
分情况讨论就好了;
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=1e3+20;
const double eps=1e-12; int n,m;
int a[N]; int main()
{
read(n);read(m);
For(i,1,n)read(a[i]);
sort(a+1,a+n+1);
if(n==1)cout<<"0";
else {
int ans=inf;
if(m>=a[n])ans=m-a[2];
else if(m<=a[1])ans=a[n-1]-m;
else
{
ans=min(ans,abs(m-a[1])+a[n-1]-a[1]);
ans=min(ans,abs(m-a[2])+a[n]-a[2]);
ans=min(ans,abs(a[n]-m)+a[n]-a[2]);
ans=min(ans,abs(a[n-1]-m)+a[n-1]-a[1]);
}
cout<<ans<<endl;
} return 0;
}
codeforces 709B B. Checkpoints(水题)的更多相关文章
- Codeforces Gym 100531G Grave 水题
Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...
- codeforces 706A A. Beru-taxi(水题)
题目链接: A. Beru-taxi 题意: 问那个taxi到他的时间最短,水题; AC代码: #include <iostream> #include <cstdio> #i ...
- codeforces 569B B. Inventory(水题)
题目链接: B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces 489A SwapSort (水题)
A. SwapSort time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- codeforces 688A A. Opponents(水题)
题目链接: A. Opponents time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- CodeForces 534B Covered Path (水题)
题意:给定两个速度,一个一初速度,一个末速度,然后给定 t 秒时间,还每秒速度最多变化多少,让你求最长距离. 析:其实这个题很水的,看一遍就知道怎么做了,很明显就是先从末速度开始算起,然后倒着推. 代 ...
- Codeforces Gym 100286I iSharp 水题
Problem I. iSharpTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...
- CodeForces 705A(训练水题)
题目链接:http://codeforces.com/problemset/problem/705/A 从第三个输出中可看出规律, I hate that I love that I hate it ...
- CodeForces Gym 100685C Cinderella (水题)
题意:给定 n 个杯子,里面有不同体积的水,然后问你要把所有的杯子的水的体积都一样,至少要倒少多少个杯子. 析:既然最后都一样,那么先求平均数然后再数一下,哪个杯子的开始的体积就大于平均数,这是一定要 ...
随机推荐
- linux环形buff模拟多线程信号量操作
互斥锁mutex变量的值非0即1,只能用来表示两种状态下的临界资源.而信号量是与之类似的,用来表示可用资源的,区别在于,信号量可以表示多个可用资源的. --值为2的信号量也就是特殊的互斥锁了. 那么下 ...
- SharpGL学习笔记(十二) 光源例子:解决光源场景中的常见问题
笔者学到光源这一节,遇到的问题就比较多了,收集了一些如下所述: (1) 导入的3ds模型,如果没有材质光照效果很奇怪.如下图 (2) 导入的3ds模型,有材质,灯光效果发暗,材质偏色,效果也很奇怪. ...
- abap number range
如有转载请注明出处:http://blog.csdn.net/donkey2004112103/archive/2009/04/13/4070996.aspx 1.sap numbe range在标准 ...
- 刚刚结束了公司EP流程,开始KMS项目开发了
刚刚结束了公司EP流程,开始KMS项目开发了 EP流程:AGpoint+MOSS+C# KMS:MOSS上的文档管理系统
- App开发流程之配置Info.plist文件
Info.plist文件控制应用的全局配置,例如bundle name,display name. 先来看一下默认创建的Info.plist文件 右键左侧的Info.plist文件,可以open as ...
- iOS 开发 - 改善APP的流畅度 (绘制股票行情)
这几天做了一个查看股票行情的app. 完成之后,当k线比较多的时候,app 对于捏合.拖动手势的反应不太流畅, 主要原因是drawRect: 干的活太多, 竟然需要40ms+, fps 自然不高 最后 ...
- C语言-06-复杂数据类型
一.数组 1> 数组的定义和初始化 定义 ① 数组定义了同种类型数据的集合 ② 定义数组时,数组必须有固定的长度 初始化 ① 如果在定义数组时,初始化数组,数组元素的个数必须是常量 ② 如果不在 ...
- 网易新闻iOS版使用的18个开源组件
转载来自:http://www.jianshu.com/p/8952944f7566 原文最后编辑时间:2015.05.19 网易新闻iOS版在开发过程中曾经使用过的第三方开源类库.组件 1.AFN ...
- Markdown 五分钟速成
为了加强后续 Wiki 开发效率,请编写人员使用规定工具按照规范进行文档的编写. Windows 用户推荐使用编辑器 MarkdownPad 下载地址:http://markdownpad.com M ...
- 为什么需要SQL Profile
为什么需要SQL Profile Why oracle need SQL Profiles,how it work and what are SQL Profiles... 使用DBMS_XPLAN. ...