点击打开链接

A. Nicholas and Permutation
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

水题,直接找最大值和最小值的位置,判断把谁放到最边上。

#include <bits/stdc++.h>
using namespace std;
int main()
{int n;cin>>n;int a[110];cin>>a[1];int mi=a[1],ma=a[1],p=1,q=1;for(int i=2;i<=n;i++){cin>>a[i];if(a[i]<mi){mi=a[i];p=i;}if(a[i]>ma){ma=a[i];q=i;}}int w1=p-1,w2=n-p,w3=q-1,w4=n-q;int w=max(w1,w2);w=max(w,w3);w=max(w,w4);cout<<w<<endl;return 0;
}

codeforces 676A Nicholas and Permutation相关推荐

  1. Codeforces Round #354 (Div. 2) A. Nicholas and Permutation

    Nicholas and Permutation time limit : 1 second memory limit: 256 megabytes 题目连接: http://www.codeforc ...

  2. codeforces 7.22 E Permutation Shift

    codeforces 7.22 E Permutation Shift 给出一个1到n的排列,每次可以交换两个数,问在交换最多m次(m <= n/3)之后能不能得到由1 2 3 - n循环右移所 ...

  3. 【CodeForces - 124C】Prime Permutation(数学,思维,小结论)

    题干: You are given a string s, consisting of small Latin letters. Let's denote the length of the stri ...

  4. 【CodeForces - 483C】Diverse Permutation(思维构造)

    题干: Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of ndistinct posit ...

  5. Codeforces 1754B.Kevin and Permutation

    1754B.Kevin and Permutation 原题地址 For his birthday, Kevin received the set of pairwise distinct numbe ...

  6. CodeForces 361B Levko and Permutation

    题意:有n个数,这些数的范围是[1,n],并且每个数都是不相同的.你需要构造一个排列,使得这个排列上的数与它所在位置的序号的最大公约数满足 > 1,并且这些数的个数恰好满足k个,输出这样的一个排 ...

  7. CodeForces - 351E Jeff and Permutation(贪心)

    题目链接:点击查看 题目大意:给出一个长度为 n 的序列,可以选择某些位置使得 a[ i ] =  - a[ i ],问逆序对最少可以是多少 题目分析:需要看出的一个关系就是,在某一对关系 ( i , ...

  8. CodeForces - 1343F Restore the Permutation by Sorted Segments(思维)

    题目链接:点击查看 题目大意:现在有一个长度为 n 的排列 p ,但排列 p 暂时对我们保密,每个样例将会给出 n - 1 个排好序后的子段,换句话说,对于 r ∈ [ 2 , n ] ,存在一个 l ...

  9. CodeForces - 618B Guess the Permutation(思维+构造)

    题目链接:点击查看 题目大意:先给出一个长度为n的序列ai,这个序列是1~n全排列中的其中一种,再给出一个n*n的矩阵,maze[i][j]=val代表min(ai,aj)=val,要求我们构造出原始 ...

  10. CodeForces 785E Anton and Permutation 分块

    题意: 有一个\(1 \sim n\)的排列\(A\),有\(q\)个询问: 交换任意两个元素的位置,求交换之后排列的逆序数 分析: 像这种不太容易用线段树,树状数组维护的可以考虑分块 每\(\sqr ...

最新文章

  1. 认识登录控件(Login、CreateUserWizard、LoginStatus和LoginName)
  2. YTKNetwork使用application json方式传递参数
  3. linux mint 13 input method of chinese
  4. 会员直推奖php程序_PHP自适应卡益源码 前台直销源码 报单费 直推奖 有内部商城...
  5. 自学计算机二级office用什么书,暑假里想要自学计算机二级office有哪些什么好的建议...
  6. linux parallel 命令,Linux 并行处理神器 GNU Parallel 简明教程
  7. 数据可视化美学形式与功能需要齐头并进
  8. python是什么-Python 是什么
  9. Centos7 搭建 Socks 服务
  10. python编程视频剪辑_MoviePy常用剪辑类及Python视频剪辑自动化
  11. Android系统启动过程-uBoot+Kernel+Android
  12. 做专业领域领航者 佳能正式推出了Professional Print Layout打印软件
  13. 安卓导入项目遇到“Sync Android SDKs”
  14. android studio迁移,AndroidStudio 一键迁移至 AndroidX
  15. 怎么查看建筑图纸?有什么技巧吗?
  16. QT图片处理+文字处理
  17. 中兴美国事件回顾:崛起的骄傲与威胁
  18. 制作千兆以太网FPGA PCB拓展板 实现基于B50610以太网摄像头采集方案
  19. python httplib [Errno 104] Connection reset by peer问题
  20. java jre 32_【JRE】JRE32/64位官方下载 V8.0 官方版-趣致软件园

热门文章

  1. 误码率与信噪比的关系matlab,误码率BER与信噪比SNR的关系解析
  2. ggggxc学习笔记---C语言代码I
  3. 2021-06-13
  4. 超声波无线充电电动牙刷方案开发设计
  5. js截取视频第一帧作为封面
  6. 涉密计算机怎么更新补丁,windows系统补丁你更新还是不更新?
  7. 量化交易零基础入门教程
  8. SQL练习题附重点函数说明--更新至21题
  9. RocketMQTemplate发送带tags的消息
  10. cf Educational Codeforces Round 47 E. Intercity Travelling