Nicholas and Permutation
time limit :

1 second

memory limit: 256 megabytes

题目连接:

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

题意

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

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

题解:

把最小的数扔到边上,或者把最大的数扔到边上

代码:

#include<bits/stdc++.h>
using namespace std;
int a[105];
int main()
{int n,pos1,pos2;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);if(a[i]==1) pos1=i;if(a[i]==n) pos2=i;}int dis1=max(n-pos1,pos1-1);int dis2=max(n-pos2,pos2-1);if(dis1>dis2) cout<<dis1;else cout<<dis2;return 0;
}

转载于:https://www.cnblogs.com/wangdongkai/p/5531792.html

Codeforces Round #354 (Div. 2) A. Nicholas and Permutation相关推荐

  1. Codeforces Round #636 (Div. 3) F. Restore the Permutation by Sorted Segments 思维 + 暴力

    传送门 文章目录 题意: 思路: 题意: n≤200n\le200n≤200 思路: 首先关注到rrr从[2,n][2,n][2,n]都出现一次,所以很明显最后一个位置只出现一次,但是这样倒着来不是很 ...

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

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

  3. Codeforces Round #354 (Div. 2)

    贪心 A Nicholas and Permutation #include <bits/stdc++.h>typedef long long ll; const int N = 1e5 ...

  4. Codeforces Round #354 (Div. 2)-Theseus and labyrint

    原文链接 题中给的迷宫有四个状态,我把每个状态对应的图都生成.用宽搜求出从原点到每个状态的迷宫的每个格子的最小距离. #include <iostream> #include <cs ...

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

    题意:给出一个n*m的地图,英雄从(xt,yt)出发,要到达敌人所在地(xm,ym).地图每个格子有设定: ^>v<代表向箭头方向有门,其他方向没门: URDL代表某个方向没门,其他方向都 ...

  6. Codeforces Round #776 (Div. 3)-D. Twist the Permutation

    原题链接:https://codeforces.com/contest/1650/problem/D 解题思路: 仔细审题,会发现对第i个数字做的操作不会影响到后面的i+1-等数字.即可以反过来从最后 ...

  7. 【贪心】Codeforces Round #436 (Div. 2) D. Make a Permutation!

    题意:给你一个长度为n的数组,每个元素都在1~n之间,要你改变最少的元素,使得它变成一个1~n的排列.在保证改动最少的基础上,要求字典序最小. 预处理cnt数组,cnt[i]代表i在原序列中出现的次数 ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #563 (Div. 2)/CF1174

    Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...

最新文章

  1. BBI:Eran Elinav组综述在微生物组研究中使用宏转录组
  2. 乱谈Qt事件循环嵌套
  3. html5 list css,使用HTML5的classList属性操做CSS类
  4. 运行 vue 报node错
  5. [转载] 启用和禁用 Reporting Services 的客户端打印和导出文件格式
  6. 【APICloud系列|35】小米应用商店版本更新
  7. [dp]最长单调递增子序列LIS
  8. 「小公式」平均数与级数
  9. 代码实现——MapReduce实现Hadoop序列化
  10. C#开发ActiveX控件及制作CAB包
  11. 打印一种拓扑排序(假定给的是有向无环图时)DFS+栈
  12. 使用 jQuery 修改 css 中带有 !important 的样式属性
  13. orl face data download
  14. matlab中pwm占空比计算代码,如何计算pwm波占空比
  15. go语言:sync.Once的用法
  16. 高仿360云盘android端的ui实现,(原创)高仿360云盘android端的UI实现 – 孤~影
  17. 互联网创业最好的时代
  18. 安卓开发面试题,一个APP从启动到主页面显示经历了哪些过程?威力加强版
  19. 【Luat-esp32】3.陀螺仪-mpu6050
  20. java audioinputstream 读取音频文件_从原始文件中获取最多x个字节的AudioInputStream(剪切音频文件)...

热门文章

  1. 计算机考研 东华大学,东华大学(专业学位)计算机技术考研难吗
  2. Excel自动转曲线图的时PHP,excel表格数据转为曲线-如何将EXCEL表中的数据生成曲线...
  3. redis desktop manager 集群_Redis Manager(2.0) —— Redis 运维利器
  4. java 非模态_统计图钻取的明细报表在非模态窗口中显示
  5. 敏捷开发一千零一夜读书笔记之敏捷初探
  6. 图的表示:如何存储微博、微信等社交网络中的好友关系
  7. nginx官方模块之http_random_index_module
  8. 发改委:扩大优质民营企业债券发行规模
  9. Node.js 使用http客户端向网站请求数据并保存
  10. Sixpack —— 支持多语言的 A/B 测试框架