CF676A Nicholas and Permutation

题目链接:CF676A Nicholas and Permutation

题意:给定数组,可以让两个数的位置交换,让最大值和最小值的位置的差的绝对值最大

先用ccc记录最大值位置,ddd记录最小值位置

然后取444种情况中绝对值最大的

第111种,ddd与第111个元素交换

第222种,ddd与第nnn个元素交换

第333种,ccc与第111个元素交换

第444种,ccc与第nnn个元素交换

代码实现还是比较简单的

#include<bits/stdc++.h>
using namespace std;
#define R register
int n,k,a=-1,b=INT_MAX,c,d;//最大值初始化为-1,最小值初始化为很大的数(2147483647)
signed main()
{scanf("%d",&n);for(R int i=0; i<n; i++){scanf("%d",&k);//无需数组存if(k>a)a=k,c=i;if(k<b)b=k,d=i;}printf("%d\n",max(max(d,abs(d-(n-1))),max(c,abs(c-(n-1)))));//此处是为了方便阅读return 0;
}

转载请说明出处

CF676A Nicholas and Permutation 题解相关推荐

  1. Codeforces Round #354 (Div. 2) A. Nicholas and Permutation

    Nicholas and Permutation time limit : 1 second memory limit: 256 megabytes 题目连接: http://www.codeforc ...

  2. Codeforces Round #640 (Div. 4)(ABCDEG题解)

    文章目录 A. Sum of Round Numbers B - Same Parity Summands C - K-th Not Divisible by n D - Alice, Bob and ...

  3. Educational Codeforces Round 131 (Rated for Div. 2) A-D题解

    题目 A. Grass Field B. Permutation C. Schedule Management D. Permutation Restoration A. Grass Field 题解 ...

  4. Codeforces Round #835 (Div. 4) B. Lost Permutation

    You are given an array a[0-n−1]a[0-n−1] of nn integers. This array is called a "valley" if ...

  5. Restoring the Permutation CodeForces - 1506E

    题目链接:E. Restoring the Permutation 题解:按字典序最小的简单一点,字典序大的较为复杂,找出字典序最大的可以通过栈,如果当前的a[i]值和a[i-1]值不相等,说明b[i ...

  6. 【Codeforces】A3组刷题记录( 43 / 43 )

    目录 A1. Combination Lock A2. Summer Camp rzt A3. Soft Drinking ★A4. Coder ★A5. GukiZ and Contest ★A6. ...

  7. Codeforces Round #354 (Div. 2)-A

    A. Nicholas and Permutation 题目链接:http://codeforces.com/contest/676/problem/A Nicholas has an array a ...

  8. asp子窗口读取父窗口数据_算法与数据结构基础 - 数组(Array)

    数组基础 数组是最基础的数据结构,特点是O(1)时间读取任意下标元素,经常应用于排序(Sort).双指针(Two Pointers).二分查找(Binary Search).动态规划(DP)等算法.顺 ...

  9. Codeforces Round #354 (Div. 2)

    贪心 A Nicholas and Permutation #include <bits/stdc++.h>typedef long long ll; const int N = 1e5 ...

  10. codeforces Good Bye 2022

    codeforces Good Bye 2022 A. Koxia and Whiteboards 题解 根据提意,每次对a数组最小元素的操作就好了,因为n,m的范围比较小,所以没必要用优先对列. # ...

最新文章

  1. 解决svn的working copy locked并且cleanup恢复不能的情况
  2. activiti源码编译
  3. Glide 源码分析与面试提问
  4. 牛客网 暑期ACM多校训练营(第一场)J.Different Integers-区间两侧不同数字的个数-离线树状数组 or 可持久化线段树(主席树)...
  5. flask html下拉列表,如何使用Flask和HTML从python列表创建下拉菜单
  6. 【BZOJ1010】【codevs1319】玩具装箱,斜率优化DP
  7. 为什么天朝互联网的三巨头是BAT
  8. 【1】windows下IOS开发基础环境搭建
  9. Python环境下如何安装爬虫需求的一些库
  10. APT攻防整理-攻击方法/工具
  11. 传统高斯模糊与优化算法(附完整C++代码)
  12. 【优化预测】基于matlab差分算法优化ANN预测【含Matlab源码 151期】
  13. 翻译: 2.6 概率论 深入神经网络 pytorch
  14. 【励志】知乎热门:我是怎么变自律的?
  15. 如何删除IE中的证书
  16. 服装标准中纰裂试验方法的比较与探讨
  17. Enhanced ShockBurst (ESB)原文翻译
  18. matlab2020a编译环境 MCR 安装步骤(非常实用)
  19. linux 移动某个文件夹及其所有子文件夹内指定类型的文件
  20. AutoPostBack属性值为True和False的含义 (即为和不和服务器交互)

热门文章

  1. 面向功利编程,面向Star开源? 一个开发者的2019反思总结
  2. 淼淼刷力扣(PTA特别版2)
  3. 【python爬虫】爬取链家二手房数据
  4. 对电话号码进行格式校验、脱密、加密、解密、掩码等的操作介绍
  5. 一份优秀的前端开发工程师简历是怎样的?
  6. 【无限互联】学员作品 豆果美食IOS客户端
  7. 国家新标准上线,妈妈再也不用担心我吃辣条啦!
  8. 开机出现recovering journal解决办法
  9. 我们到底能从《别逗了,费曼先生》中学到什么?
  10. 动态规划经典例题——最长公共子序列和最长公共子串(python)