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. 内核定时器的使用(好几个例子add_timer)【转】

    转自:http://blog.csdn.net/jidonghui/article/details/7449546 LINUX内核定时器是内核用来控制在未来某个时间点(基于jiffies)调度执行某个 ...

  2. Fiddler是最强大最好用的Web调试工具

    Fiddler是最强大最好用的Web调试工具之一,它能记录所有客户端和服务器的http和https请求,允许你监视,设置断点,甚至修改输入输出数据. 使用Fiddler无论对开发还是测试来说,都有很大 ...

  3. Javascript中的Callback方法浅析

    什么是callback?  回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用为调用它所指向的函数时,我们就说这是回调函数.回调函数不是由该函数 ...

  4. 最长子串(Leetcode-3 Longest Substring Without Repeating Characters)

    Question: Given a string, find the length of the longest substring without repeating characters. Exa ...

  5. 基于gRpc的远程服务框架

    作为一个新搭建的软件团队,底层技术尤为重要.为了以后更好的面向不同的项目需求,满足不断变化的需求,决定着手搭建一套RPC系统.为了更好的兼容以后部门其他语言的使用,选择了开源框架gRpc. gRpc ...

  6. 首次加载进来DEV控件列表第一行颜色总是不对,后台代码显示的数据正确

    1:行改变的颜色正确的颜色: 1.1颜色效果如下图: 1.2:设置行改变颜色: 2:结果首次加载第一行颜色为: 3:解决方案: 3.1 :Views-->OptionsSelection --& ...

  7. Java字符串常见实例与函数

    字符串比较 字符串函数 compareTo (string) ,compareToIgnoreCase(String) 及 compareTo(object string) 来比较两个字符串,并返回字 ...

  8. JS倒计时、计时

    倒计时 倒计时常用于发送验证码 前端代码如下: <!DOCTYPE html> <html> <head> <title>倒计时.计时</titl ...

  9. java对对象排序

    一.前言 有时我们需要对类按照类中的某一个属性(或者多个属性)来对类的对象进行排序,有两种方法可以实现,一种方法是类实现Comparable<T>接口,然后调用Collections.so ...

  10. linux下svn命令的使用

    1.将文件checkout到本地目录   svn checkout path(path是服务器上的目录)    例如:svn checkout svn://192.168.1.1/pro/domain ...