CF676A Nicholas and Permutation 题解
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 题解相关推荐
- Codeforces Round #354 (Div. 2) A. Nicholas and Permutation
Nicholas and Permutation time limit : 1 second memory limit: 256 megabytes 题目连接: http://www.codeforc ...
- 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 ...
- Educational Codeforces Round 131 (Rated for Div. 2) A-D题解
题目 A. Grass Field B. Permutation C. Schedule Management D. Permutation Restoration A. Grass Field 题解 ...
- 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 ...
- Restoring the Permutation CodeForces - 1506E
题目链接:E. Restoring the Permutation 题解:按字典序最小的简单一点,字典序大的较为复杂,找出字典序最大的可以通过栈,如果当前的a[i]值和a[i-1]值不相等,说明b[i ...
- 【Codeforces】A3组刷题记录( 43 / 43 )
目录 A1. Combination Lock A2. Summer Camp rzt A3. Soft Drinking ★A4. Coder ★A5. GukiZ and Contest ★A6. ...
- Codeforces Round #354 (Div. 2)-A
A. Nicholas and Permutation 题目链接:http://codeforces.com/contest/676/problem/A Nicholas has an array a ...
- asp子窗口读取父窗口数据_算法与数据结构基础 - 数组(Array)
数组基础 数组是最基础的数据结构,特点是O(1)时间读取任意下标元素,经常应用于排序(Sort).双指针(Two Pointers).二分查找(Binary Search).动态规划(DP)等算法.顺 ...
- Codeforces Round #354 (Div. 2)
贪心 A Nicholas and Permutation #include <bits/stdc++.h>typedef long long ll; const int N = 1e5 ...
- codeforces Good Bye 2022
codeforces Good Bye 2022 A. Koxia and Whiteboards 题解 根据提意,每次对a数组最小元素的操作就好了,因为n,m的范围比较小,所以没必要用优先对列. # ...
最新文章
- 解决svn的working copy locked并且cleanup恢复不能的情况
- activiti源码编译
- Glide 源码分析与面试提问
- 牛客网 暑期ACM多校训练营(第一场)J.Different Integers-区间两侧不同数字的个数-离线树状数组 or 可持久化线段树(主席树)...
- flask html下拉列表,如何使用Flask和HTML从python列表创建下拉菜单
- 【BZOJ1010】【codevs1319】玩具装箱,斜率优化DP
- 为什么天朝互联网的三巨头是BAT
- 【1】windows下IOS开发基础环境搭建
- Python环境下如何安装爬虫需求的一些库
- APT攻防整理-攻击方法/工具
- 传统高斯模糊与优化算法(附完整C++代码)
- 【优化预测】基于matlab差分算法优化ANN预测【含Matlab源码 151期】
- 翻译: 2.6 概率论 深入神经网络 pytorch
- 【励志】知乎热门:我是怎么变自律的?
- 如何删除IE中的证书
- 服装标准中纰裂试验方法的比较与探讨
- Enhanced ShockBurst (ESB)原文翻译
- matlab2020a编译环境 MCR 安装步骤(非常实用)
- linux 移动某个文件夹及其所有子文件夹内指定类型的文件
- AutoPostBack属性值为True和False的含义 (即为和不和服务器交互)