日韩性视频-久久久蜜桃-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ò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 熟妇人妻中文字幕 | 国产免费观看久久黄av片 | 国产精品对白 | 日韩一区二区在线免费观看 | 久久综合丁香 | 欧美午夜精品理论片a级按摩 | 在线免费看mv的网站入口 | 免费av不卡在线观看 | 动漫美女舌吻 | 女优一区二区三区 | 天堂视频网 | 免费男女乱淫真视频免费播放 | videos另类灌满极品另类 | 午夜做爰xxxⅹ性高湖视频美国 | 欧美99久久精品乱码影视 | 国产刺激视频 | 欧美亚洲国产一区二区三区 | 黄色免费在线观看网站 | 香蕉蜜桃视频 | 欧洲激情网 | 国产不卡视频在线播放 | 亚洲最大的成人网 | 18国产免费视频 | 亚洲人xxx| 91嫩草影视 | 日韩在线一二三区 | 青苹果av| 日韩欧美一区二区三区久久婷婷 | 亚洲色偷偷综合亚洲av伊人 | 久草在| 欧美国产精品一区二区 | www.97av| 国产精品作爱 | 婷婷视频一区二区三区 | 久久香蕉av | 97国产超碰 | 久久久久久国产精品一区 | 黄色一区二区三区 | 精品人妻人伦一区二区有限公司 | 午夜精品福利在线观看 | h在线 | 国产一区二区视频在线免费观看 | 欧美激情一区二区三区p站 欧美mv日韩mv国产网站app | 韩日黄色片 | 国产精品情侣 | 亚洲女女做受ⅹxx高潮 | www操| 日韩av网址在线观看 | 欧美日韩一区二区久久 | 精品日韩av | 日本三级一区二区 | 亚洲一区二区三区在线视频观看 | 51热门大瓜今日大瓜 | 日韩欧美在线视频免费观看 | 国产精品永久免费 | 一级黄色片免费在线观看 | 无码人妻一区二区三区av | 国产人人爱 | 日韩欧美中文在线 | 一区二区三区丝袜 | 日韩综合在线视频 | 成a人片亚洲日本久久 | 桃色综合网 | 青春草在线视频免费观看 | 美女100%露胸无遮挡 | 深夜视频免费在线观看 | 精品国产一区二区三区av性色 | 色无极亚洲 | 中文字幕国内自拍 | 午夜色综合 | 非洲一级黄色片 | 免费超爽大片黄 | 日本中文字幕高清 | 黑丝袜av | 久久精品欧美一区二区 | 国产精品一区免费 | 黄色片视频在线观看 | 国产一区二区三区中文字幕 | 欧美激情区 | 天堂аⅴ在线最新版在线 | 美女视频污 | 97热视频| 日韩av一区二区三区 | 日韩欧美精品 | 麻豆69| 日本五十路在线 | 成人免费视频网站在线看 | 国产乱淫a∨片免费视频 | 啊v视频在线观看 | 免费视频二区 | 丰满熟女人妻一区二区三 | 狠狠操很很干 | 超碰人人91 | 无码gogo大胆啪啪艺术 | 99久久99久久精品国产片 | 强睡邻居人妻中文字幕 | 永久免费AV无码网站韩国毛片 | 女仆乖h调教跪趴1v1 | 精品久久久久久无码中文野结衣 |