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. VC++ 模块与资源分离

    在一些开发过程中,需要模块支持中英文语言切换,比较好的实现方式是从模块中将资源分离出来,做成中英文两个资源dll,根据需要加载不同的dll从而实现切换不同的语言显示. 新建一个资源dll文件,选择Wi ...

  2. BestCoder21 1002.Formula 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5139 题目意思:给出一个数 n,求出 f(n). 可以发现有以下规律: f(1) = 1! f(2) ...

  3. JavaBean中set/get的命名规范

    今天遇到了这样的问题,在jsp取session中的值时,取不到.有个SessionUser对象,该对象有个uId属性,set/get方法为setUId/getUId,在jsp页面通过el表达式取值${ ...

  4. 关于v$datafile中system表空间的status值始终为system

    http://docs.oracle.com/cd/B19306_01/server.102/b14237/dynviews_1076.htm#REFRN30050 http://blog.itpub ...

  5. .net学习之委托和事件

    1.什么是委托通俗的说:委托就是一个能够存储符合某种格式(方法签名)的方法的指针的容器上传图片: 2.委托语法准备一个方法:string Hello(string userName){} string ...

  6. 玩转SSRS第十篇---自定义代码

    提到SSRS 那么就不得不提一下自定义代码的功能,通过自定义代码,有时候可以解决一些比较复杂的问题,比如将让指定的数据行应用指定的属性值.此篇将演示如何通过简单结构的自定义代码进行报表样式的基本设计. ...

  7. Tabular Model下的ADOMD.NET

    ADOMD.NET是一套对象架构体系,它包含需要向SSAS数据库做访问的一切支持的对象和方法.很多微软官方以及第三方的SSAS客户端应用都是通过这个对象来操作数据. 多维模式的ADOMD.NET在我以 ...

  8. Java Hour 66 Spring 相关

    这章简单的来了解下Spring 和 Hibernate 是如何勾搭在一起的. <bean id="sessionFactory" class="org.spring ...

  9. WCF----Stream对象限制操作

    WCF支持Stream操作,尤其对于传递size过大的消息而言,如要考虑传递消息的效率,WCF推荐通过Stream进行操作.然而,WCF Stream操作规定了一些限制,在我们编写相关程序时,需要特别 ...

  10. QQ的账号登录及api操作

    .qq.php <?php /** * PHP Library for qq.com * * @author */ class qqPHP { function __construct($app ...