A. Nicholas and Permutation

题目连接:

http://www.codeforces.com/contest/676/problem/A

Description

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.

Sample Input

5

4 5 1 3 2

Sample Output

3

Hint

题意

给你一个n的排列,然后你可以改变一次这个排列的位置

你需要使得最小的数和最大的数距离最大,问你这个距离是多少

题解:

显然就是把最小的数扔到边上,或者把最大的数扔到边上就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 106; int a[maxn],b[maxn]; int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
int ans1 = 0,ans2 = 0;
for(int i=1;i<=n;i++)
{
if(a[i]==1)ans1=i;
if(a[i]==n)ans2=i;
}
int ans=max(abs(n-ans2),abs(ans2-1));
ans=max(ans,abs(n-ans1));
ans=max(ans,abs(ans1-1));
cout<<ans<<endl;
}

Codeforces Round #354 (Div. 2) A. Nicholas and Permutation 水题的更多相关文章

  1. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  2. Codeforces Round #290 (Div. 2) A. Fox And Snake 水题

    A. Fox And Snake 题目连接: http://codeforces.com/contest/510/problem/A Description Fox Ciel starts to le ...

  3. Codeforces Round #322 (Div. 2) A. Vasya the Hipster 水题

    A. Vasya the Hipster Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/581/p ...

  4. Codeforces Round #373 (Div. 2) B. Anatoly and Cockroaches 水题

    B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly liv ...

  5. Codeforces Round #368 (Div. 2) A. Brain's Photos 水题

    A. Brain's Photos 题目连接: http://www.codeforces.com/contest/707/problem/A Description Small, but very ...

  6. Codeforces Round #359 (Div. 2) A. Free Ice Cream 水题

    A. Free Ice Cream 题目连接: http://www.codeforces.com/contest/686/problem/A Description After their adve ...

  7. Codeforces Round #355 (Div. 2) A. Vanya and Fence 水题

    A. Vanya and Fence 题目连接: http://www.codeforces.com/contest/677/problem/A Description Vanya and his f ...

  8. Codeforces Round #384 (Div. 2) A. Vladik and flights 水题

    A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...

  9. Codeforces Round #379 (Div. 2) D. Anton and Chess 水题

    D. Anton and Chess 题目连接: http://codeforces.com/contest/734/problem/D Description Anton likes to play ...

随机推荐

  1. scp加端口号

    scp -P 21110 root@192.168.0.1:/home/abc.txt root@192.168.0.2:/root 注意: 参数-P 的位置一定要紧跟在scp命令后面 参数-P 指的 ...

  2. 建立ARM交叉编译环境 (arm-none-linux-gnueabi-gcc with EABI)【转】

    转自:http://lib.csdn.net/article/embeddeddevelopment/60172?knId=886 建立ARM交叉编译环境 (arm-none-linux-gnueab ...

  3. linux查看目录的四种方法(ls只显示目录)【转】

    1.ls -d * amosli@amosli-pc:~$ ls -d * %APPDATA% develop many sorted.txt workspace bank Documents Mus ...

  4. 使用postman做接口测试(三)

    三,接口用例的设计 个人感觉用例的设计才是重要的哈,网上查了一些资料总结了一下 1.业务流程测试 通过性验证: 1, 按照接口文档上的参数,正常传参,是否可以返回正确的结果 2, 是否满足前提条件,比 ...

  5. MySQL -- SQL 语句

    一. 数据库(Database)操作 创建数据库 create database 数据库名 create database 数据库名 character set 字符集 查看数据库 查看数据库服务器中 ...

  6. linux中查看结构体和宏

    1.进入目录/usr/include cd /usr/include/ 2.生成ctags文件sudo make ctags -R 3.vim -t 结构体(宏)名称 4.找到相应的宏或者结构体 5. ...

  7. 使用apt-get安装Nginx

    Ubuntu 18.04,Nginx 1.14.0, 一直想在Linux上安装Nginx,一直没找到契机,很大原因是自己不熟悉,Ubuntu没安装好吧!今天下午学习了Ubuntu安装软件的一些资料,那 ...

  8. IntelliJ IDEA + Tomcat ;On Upate Action 与 On Frame Deactivation

    On Upate Action 与 On Frame Deactivation  这两个选项的设置,依赖于 项目的部署方式 是war包 还是 exploded ,看下面的gif: 这里实在是太灵活了, ...

  9. POJ 3280 Cheapest Palindrome(区间DP求改成回文串的最小花费)

    题目链接:http://poj.org/problem?id=3280 题目大意:给你一个字符串,你可以删除或者增加任意字符,对应有相应的花费,让你通过这些操作使得字符串变为回文串,求最小花费.解题思 ...

  10. Luogu P1566 【加等式】

    看到这道题,我们首先注意到“找出其所有的加等式的个数”,自然地考虑运用计数DP求出若干数相加的和的个数 考虑将每个元素排序后DP处理若干数相加的和的个数 用f[i]表示 对于一个数a[i],对于前i- ...