日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Codeforces Round #354 (Div. 2)-A

發(fā)布時(shí)間:2025/6/15 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Codeforces Round #354 (Div. 2)-A 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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.

?

題意:給定一個(gè)序列,只能交換1次[一次交換任意的2個(gè)數(shù)的位置],問(wèn)最大值和最小值的距離最大是多少?

思路:因?yàn)橹荒芙粨Q一次。所以肯定把某一個(gè)[最大值/最小值]反正最邊是最優(yōu)的。

#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=100+5; int num[MAXN]; int main() { #ifdef kiritofreopen("in.txt","r",stdin);freopen("out.txt","w",stdout); #endifint n;while(~scanf("%d",&n)){int MAX_pos,MIN_pos;for(int i=1;i<=n;i++){scanf("%d",&num[i]);if(num[i]==1){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)-1));}return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/kirito520/p/5550331.html

總結(jié)

以上是生活随笔為你收集整理的Codeforces Round #354 (Div. 2)-A的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。