A. Nicholas and Permutation
题目链接:http://codeforces.com/contest/676/problem/A

Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.

Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 100) — the size of the permutation.

The second line of the input contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n), where ai is equal to the element at the i-th position.

Output

Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.

Examples
input
5
4 5 1 3 2
output
3
input
7
1 6 5 3 4 7 2
output
6
input
6
6 5 4 3 2 1
output
5
Note

In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.

In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.

In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.

题意:给定一个序列,只能交换1次[一次交换任意的2个数的位置],问最大值和最小值的距离最大是多少?

思路:因为只能交换一次。所以肯定把某一个[最大值/最小值]反正最边是最优的。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<bitset>
using namespace std;
#define INF 0x3f3f3f3f
#define PI 3.14159
const int MAXN=+;
int num[MAXN];
int main()
{
#ifdef kirito
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int n;
while(~scanf("%d",&n)){
int MAX_pos,MIN_pos;
for(int i=;i<=n;i++)
{
scanf("%d",&num[i]);
if(num[i]==){MIN_pos=i;}
if(num[i]==n){MAX_pos=i;}
}
printf("%d\n",max(n-min(MAX_pos,MIN_pos),max(MAX_pos,MIN_pos)-)); }
return ;
}

Codeforces Round #354 (Div. 2)-A的更多相关文章

  1. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  2. Codeforces Round #354 (Div. 2)-D

    D. Theseus and labyrinth 题目链接:http://codeforces.com/contest/676/problem/D Theseus has just arrived t ...

  3. Codeforces Round #354 (Div. 2)-C

    C. Vasya and String 题目链接:http://codeforces.com/contest/676/problem/C High school student Vasya got a ...

  4. Codeforces Round #354 (Div. 2)-B

    B. Pyramid of Glasses 题目链接:http://codeforces.com/contest/676/problem/B Mary has just graduated from ...

  5. Codeforces Round #354 (Div. 2) D. Theseus and labyrinth

    题目链接: http://codeforces.com/contest/676/problem/D 题意: 如果两个相邻的格子都有对应朝向的门,则可以从一个格子到另一个格子,给你初始坐标xt,yt,终 ...

  6. Codeforces Round #354 (Div. 2) C. Vasya and String

    题目链接: http://codeforces.com/contest/676/problem/C 题解: 把连续的一段压缩成一个数,对新的数组求前缀和,用两个指针从左到右线性扫一遍. 一段值改变一部 ...

  7. Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)

    题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...

  8. Codeforces Round #354 (Div. 2) E. The Last Fight Between Human and AI 数学

    E. The Last Fight Between Human and AI 题目连接: http://codeforces.com/contest/676/problem/E Description ...

  9. Codeforces Round #354 (Div. 2) D. Theseus and labyrinth bfs

    D. Theseus and labyrinth 题目连接: http://www.codeforces.com/contest/676/problem/D Description Theseus h ...

随机推荐

  1. Xcode无法启动ios模拟器的问题

    一.问题描述 开发过程需要来回切换ios模拟器调试程序,开始在iPhone 4s下调试,然后切换到iPhone 6s Plus,再切换回iPhone 4s,遇到无法启动ios模拟器.错误提示如下: 二 ...

  2. 为Kindeditor控件添加图片自动上传功能

    Kindeditor是一款功能强大的开源在线HTML编辑器,支持所见即所得的编辑效果.它使用JavaScript编写,可以无缝地与多个不同的语言环境进行集成,如.NET.PHP.ASP.Java等.官 ...

  3. mysql常用函数整理

    一.数学函数 数学函数主要用于处理数字,包括整型.浮点数等. ABS(x) 返回x的绝对值 ) -- 返回1 CEIL(x),CEILING(x) 返回大于或等于x的最小整数 SELECT CEIL( ...

  4. objective-c数组

     1 #pragma mark -----------数组的初始化方式--------------  2 //        insert code here...  3 //        NSLo ...

  5. python基础——调试

    python基础——调试 程序能一次写完并正常运行的概率很小,基本不超过1%.总会有各种各样的bug需要修正.有的bug很简单,看看错误信息就知道,有的bug很复杂,我们需要知道出错时,哪些变量的值是 ...

  6. springmvc上传List,

    @RequestMapping("pay") public ModelAndView pay(String orderNo, TransactionDTO transaction, ...

  7. NYOJ题目64鸡兔同笼

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAsAAAAIZCAIAAAAnfB5fAAAgAElEQVR4nO3dO1LjygIG4LsJchZC7I ...

  8. python异步爬虫

    本文主要包括以下内容 线程池实现并发爬虫 回调方法实现异步爬虫 协程技术的介绍 一个基于协程的异步编程模型 协程实现异步爬虫 线程池.回调.协程 我们希望通过并发执行来加快爬虫抓取页面的速度.一般的实 ...

  9. android HTTPclient

    Apache包是对android联网访问封装的很好的一个包,也是android访问网络最常用的类. 下面分别讲一下怎么用HttpClient实现get,post请求. 1.Get 请求 1 2 3 4 ...

  10. C#接扣和抽象类

    什么是接口? 接口是包含一组虚方法的抽象类型,其中每一种方法都有其名称.参数和返回值.接口方法不能包含任何实现,CLR允许接口可以包含事件.属性.索引器.静态方法.静态字段.静态构造函数以及常数.但是 ...