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 个杯子,里面有不同体积的水,然后问你要把所有的杯子的水的体积都一样,至少要倒少多少个杯子. 析:既然最后都一样,那么先求平均数然后再数一下,哪个杯子的开始的体积就大于平均数,这是一定要 ...
随机推荐
- mybatis mapper association collection
1.Question Description: sometimes, POJO bean contains another bean or collection as property, it's s ...
- 功放AUX接口解析
功放上的AUX输入端口就是音频输入端口,用来连接音频输出设备:PC机上声卡.MP3播放器.CD机等
- windows 7文件误删shift+delete后找回
昨天要还电脑了,结果脑子一抽,某个目录还没拷贝,shift+delete了整个目录,删除到一半,完了...我的源码都在里面还没出来啊...这TMD要命啊... 赶紧搜了一把,windows文件误删恢复 ...
- 为什么不推崇复杂的ORM
上一篇文章写完,回复的人很多,有的说的很中肯,有的貌似只是看到文章的标题就进来写评论的!还有人问为什么我要屏蔽掉[反对]按钮,因为谁写文章都是为了分享,都在说出自己的心得体会.不过由于大家遇到的项目, ...
- 为七牛云存储开发的PHP PEAR 包:Services_Qiniu
七牛云存储Qiniu Resource (Cloud) Storage:用于存储图片.apk等静态资源. 优点: 1.使用七牛带宽和CDN,速度快,不占用开发者服务器. 2.支持图片任意格式.任意分辨 ...
- angular 指令——时钟范例
<html> <head> <meta charset='utf-8'> <title>模块化</title> <script typ ...
- [Android]编译错误:Could not get unknown property 'release' for SigningConfig container
使用Gradle进行安卓编译时,出现如下错误: Could not get unknown property 'release' for SigningConfig container. 原因: 在主 ...
- 【读书笔记】iOS-自动释放池
一,NSObject类提供了一个autorelease方法: -(id)autorelease; 该方法预先设定了一条将来在某个时间发送的release消息,其返回值是接收消息的对象.retain消息 ...
- UITabBarController的创建等基本方法
#import "AppDelegate.h" @interface AppDelegate () <UITabBarControllerDelegate> @end ...
- 初识UIScrollView
RootView.m #import "RootView.h" #define YHColor [UIColor colorWithRed:arc4random() % 256 / ...