Codeforces 比赛代码记录及心得
来源:互联网 发布:java统计报表怎么做 编辑:程序博客网 时间:2024/05/19 02:19
Codeforces Round #354 (Div. 2)
纪念一下自己差劲的适应能力,cf,要锻炼自己,适应能力很关键!!!
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.
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.
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
54 5 1 3 2
3
71 6 5 3 4 7 2
6
66 5 4 3 2 1
5
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<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;int main(){ int n,a[105]; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); int maxn=1,minn=1; for(int i=2;i<=n;i++) { if(a[i]>a[maxn]) maxn=i; if(a[i]<a[minn]) minn=i; } if(maxn>minn) { if(n-maxn>minn-1) printf("%d\n",n-minn); else printf("%d\n",maxn-1); } else { if(maxn-1>n-minn) printf("%d\n",minn-1); else printf("%d\n",n-maxn); } return 0;}
- Codeforces 比赛代码记录及心得
- codeforces比赛记录
- 比赛心得
- 比赛心得
- 记录第一次Codeforces Round #250 (Div. 2)的比赛
- 比赛记录
- 比赛记录
- 昨日比赛心得
- 2016年蓝桥杯比赛心得
- 【比赛心得】NOIP2016总结
- 大作业心得记录及错误分析
- WiFi 移植记录及心得 <一>
- WiFi 移植记录及心得 <二>
- 比赛小结:codeforces#169
- 比赛小结:codeforces#170
- 比赛小结:codeforces #171
- 比赛小结:codeforces #174
- 比赛小结:codeforces #175
- 数据库资源管理器(Oracle Database Resource Manager)
- swift版QQ音乐播放器(二)
- css学习笔记(一)
- LeetCode 30. Substring with Concatenation of All Words(所有单词的连接)
- Eclispse 更换主题Theme
- Codeforces 比赛代码记录及心得
- leetcode 350. Intersection of Two Arrays II
- 推送通知的跳转
- 百度首页(HTML5)
- mono中的内存泄漏和WeakReference(弱引用)的使用
- Andrid5.0新特性——SVG(可缩放矢量图)
- ubuntu 14.04 利用ap-hotspot建立wifi热点失效
- uva 524 - Prime Ring Problem
- codeforces 675-E Trains and Statistic 线段树+dp