Codeforces Round #354 (Div. 2) A Nicholas and Permutation
来源:互联网 发布:金玉满堂 知乎 编辑:程序博客网 时间:2024/06/09 16:16
思路:水题,考虑和第一个和最后一个位置交换就好啦
#include<bits\stdc++.h>using namespace std;int main(){int n;int a[105];scanf("%d",&n);int Minpos = 0;int Maxpos = 0;for(int i = 1;i<=n;i++){scanf("%d",&a[i]);if(a[i]==1)Minpos = i;if(a[i]==n)Maxpos = i;}if(Maxpos -Minpos == n-1)printf("%d\n",n-1);else{int ans = max(n-Minpos,n-Maxpos);ans = max(ans,Minpos-1);ans = max(ans,Maxpos-1);printf("%d\n",ans);}}
0 0
- Codeforces Round #354 (Div. 2)767A. Nicholas and Permutation
- Codeforces Round #354 (Div. 2) A Nicholas and Permutation
- Codeforces Round #354 (Div. 2) A Nicholas and Permutation(水题)
- Codeforces Round #354 (Div. 2)-Nicholas and Permutation
- 【Codeforces Round 354 (Div 2)A】【水题 贪心】Nicholas and Permutation 恰好交换一次的pos[n]-pos[1]
- codeforces 676A Nicholas and Permutation
- CodeForces 676A Nicholas and Permutation
- 【CodeForces 676】A - Nicholas and Permutation
- codeforces 676A Nicholas and Permutation
- A. Nicholas and Permutation
- CodeForces - 676A Nicholas and Permutation (模拟) 水
- CodeForces 676A Nicholas and Permutation(移动数字游戏)
- Codeforces Round #436 (Div. 2)D. Make a Permutation! codeforces-864D. Make a Permutation!
- Codeforces Round #144 (Div. 2)---A. Perfect Permutation
- D. Make a Permutation! (Codeforces Round #436 (Div. 2))
- Codeforces Round #436 (Div. 2) D. Make a Permutation!
- Codeforces Round #436 (Div. 2) Make a Permutation!
- Codeforces Round #436 (Div. 2)-贪心-D. Make a Permutation!
- 使用KOG数据库进行注释
- Codeforces Round#333 div.1 D Acyclic Organic Compounds
- 研究4.4的进程的保活
- linker command failed with exit code 1 (use -v to see invocation)报错
- JavaEE的十大安全控制
- Codeforces Round #354 (Div. 2) A Nicholas and Permutation
- 悲观锁与乐观锁简单介绍
- 整数、区间与区间端点
- spring must know
- Ubuntu 电脑过热
- mybatis-3.4.0---资源获取系列-ClassLoader操作
- PHP页面跳转三种实现方法
- Relationship between two numbers【2】
- 编程之美-数组除法