codeforces 676A Nicholas and Permutation

【CodeForces 676】A - Nicholas and Permutation #include #include #include #include #include using namespace std; #define maxn 110 int n; int a[maxn]; int p1,p2; int main(void) { cin>>n; for(int i=1;i>a[i]; for(int i=1;i<=n;i++) { if(a[i]==1) 阅读详情

A. Nicholas and Permutation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Nicholas has an array a that containsn distinct integers from1 to n. In other words, Nicholas has a permutation of sizen.

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 integern (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 thei-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 elements1 and 2.

In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap7 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 swap5 and 2.



#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>

using namespace std;

int a[100];

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	int maxn = -1, minn = 0x7fffffff, ia = 0, in = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] > maxn) {
			maxn = a[i];
			ia = i;
		}
		if (a[i] < minn) {
			minn = a[i];
			in = i;
		}
	}
	if (ia == 0 || ia == n - 1 || in == 0 || in == n - 1) {
		cout << n - 1 << endl;
	} else {
		cout << max(max(in, ia), max(n - 1 - in, n - 1 - ia)) << endl;
	}
	return 0;
}




手把手教你玩转服务器芯片架构​专栏--​​3.5 实战案例:用SystemC搭建一个多核服务器芯片的NoC模型(含流量分配与延迟仿真)​ 通过SystemC搭建多核NoC模型,可深入验证流量分配策略与延迟特性。实际工程中需结合FPGA原型验证(如Xilinx Alveo)进行时序收敛分析,并通过参数化设计适配不同服务器芯片需求。 阅读详情

相关推荐

Vivado FFT IP核避坑指南:从Matlab数据生成到FPGA验证的完整流程

本文详细解析了Vivado FFT IP核从Matlab数据生成到FPGA验证的完整流程,重点解决跨平台数据一致性、IP核配置陷阱和验证方法论等核心问题。通过实战案例和避坑指南,帮助工程师高效实现FFT运算的硬件验证,确保结果与Matlab的误差控制在0.3%以内。

weixin_42543046的博客 395

codeforces 676A (水题)

A. Nicholas and Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nicholas has an array a that con

morejarphone~ 524

NVIDIA显卡在Linux下的功率限制问题:RTX 3060 Laptop的解决方案与避坑指南

本文针对NVIDIA RTX 3060 Laptop显卡在Linux系统下遭遇功率限制的问题,提供了详细的诊断与解决方案。通过使用nvidia-smi工具监控显卡状态,并重点介绍了通过升级驱动、启用nvidia-powerd服务来激活Dynamic Boost 2.0功能,从而安全、智能地解锁额外显卡功率,有效提升性能。

weixin_29290947的博客 634

【Codeforces Round 354 (Div 2)A】【水题 贪心】Nicholas and Permutation 恰好交换一次的pos[n]-pos[1]

A. Nicholas and Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nicholas has an array a that con

snowy_smile的博客 847

AURIX TC397开发板到手第一步:用iLLD库驱动LED流水灯(附完整代码)

本文详细介绍了如何使用英飞凌AURIX TC397开发板和iLLD库实现LED流水灯效果。从开发环境配置到硬件连接,再到完整的代码实现,逐步引导开发者完成项目。文章还提供了优化建议和常见问题解决方案,帮助嵌入式开发新手快速上手。

weixin_30911451的博客 390

ICS v9.5 OverbyteIcsWSocket.pas 整体架构分析

核心架构:OverbyteIcsWSocket.pas 是 Internet Component Suite (ICS) 的基础网络组件单元,提供跨平台 Winsock API 封装,支持TCP/UDP 客户端/服务器,DNS 解析和Raw Socket。在 v9.5 中,SSL/TLS 代码已分离至 OverbyteIcsSslBase.pas 等单元,使核心单元更精简,专注于非加密 socket 操作。

sonadorje的专栏 991

Nicholas and Permutation

A. Nicholas and Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nicholas has an array a that contains n

nuc_Sheryl的博客 503

WRF后处理:python cartopy绘制土地利用/土地分类图//python绘制WRF下垫面类型(以北极为例)

下垫面类型对于WRF的地表过程十分重要,而在我们研究WRF的地表过程之前,需要对输入的土地利用类型进行一些绘制,以便后续的修改。LU_MODIS21函数定义了绘制的土地类型、标签与对应色标,我们使用时,直接引用LU_MODIS21()即可返回。其实很简单,只要将你拥有的土地类型数据提取出来,将原本函数中的labels和C切片,重新定义色标再绘制即可。在这里,我将以北极地区为例,绘制北极地区的WRF下垫面数据,我使用的MODIS21这类。

weixin_43750300的博客 3856

agent配置

agent2.sources=s1 agent2.channels=c1 agent2.sinks=k1 agent2.sources.s1.type = spooldir agent2.sources.s1.spoolDir =/var/log/hutxlog agent2.sources.s1.fileHeader =true agent2.sources.s1.fileHeade

lskyne的专栏 1万+

三相逆变器双pi控制器参数如何调节_光伏逆变器短路特性简析

1前言短路故障相对于其他故障类型来说是比较常见的,不同的设备的短路故障,大了讲都一样,细了说各有千秋,今天我们主要聊聊光伏逆变器的短路特征。电力系统中的电源,传统意义是指的是并入电力系统的同步发电机。但随着分布式发电技术的发展,各种形式的发电装置并入电力系统。按照分布式电源并网的方式,我们大致可以分为以下三类:➤通过旋转电机和变流器并联并网的电源,主要指双馈风力发电系统;➤仅仅通过变流器...

weixin_39901404的博客 1732

eNSP常见故障处理

eNSP无法启动设备一直停在#井号的问题的解决方案?

lvshiliang123的博客 2万+

关于agent行为

为了响应不同的外部事件,Agent必须能够执行几个并行的任务.为了使Agent管理更加有效率,每个JADE Agent都由一个单独的执行线程组成,并且它的任务都是模型化的,可以作为Behaviour的对象来执行.同样可以执行多线程的Agent,但是JADE并没有对此提供特别的支持. 想要执行一个基于Agent的任务,开发者应该定义一个或者更多Behaviours子类,然后,实例化它们,并把任务对

蓝月流星 的专栏 3237

【系统移植】 移植主线U-Boot(v2024.01-rc3)到RK3399

[系统移植] 移植主线U-Boot(v2024.01-rc3)到RK3399

Systemcall名屋 1003

CodeForces 676A Nicholas and Permutation

A. Nicholas and Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Nicholas has an array a that con

Calm微笑 522

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Codeforces--676A--Nicholas and Permutation

题目描述: 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...

猩猩是个好程序员的博客 213

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

CodeForces - 676A Nicholas and Permutation (模拟) 水

 CodeForces - 676A Nicholas and Permutation Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Nicholas has

yanghui07216的博客 882

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

CodeForces 676A Nicholas and Permutation(移动数字游戏)

http://codeforces.com/problemset/problem/676/A A. Nicholas and Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input

Shyazhut 579

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

http://codeforces.com/problemset/problem/676/A A. Nicholas and Permutation time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Nichola

linlinsong—ACM界蒟水! 673

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

题目链接:http://codeforces.com/contest/676/problem/A 题意:给一个1~n的序列,可以交换一次任意两个数,求交换后1和n的最远的距离#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> #include<math.h> #include<queue> #inc

humeay的博客 271

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

Nicholas and Permutation time limit : 1 second memory limit:256 megabytes 题目连接: http://www.codeforces.com/contest/676/problem/A Description Nicholas has an arrayathat con...

weixin_30415801的博客 117

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

A. Nicholas and Permutation 题目连接: http://www.codeforces.com/contest/676/problem/A Description Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a perm...

weixin_33674437的博客 98

HTTP STATUS CODE: 521的解决办法

一、遇到的问题 在使用Java程序访问一个PDF文件的URL时,发现无法下载该PDF文件,加上各种header也不行,然后看程序的response.getStatusLine(),发现是一个以前从未见到过的错误:HTTP/1.1 521 。 乍一看是500系列的,对面的服务崩了?但是复制url到浏览器地址栏,发现还是可以正常浏览这个PDF的。 于是清除浏览器缓存,重新访问这个URL,用大鲨鱼(wi...

wangdepei的博客 3万+

Agent 监控配置说明

Agent 监控配置说明Linux安装Agent1.查看系统版本查看系统版本uname -a根据系统版本下载对应的zabbix-agent版本安装 下载地址:http://repo.zabbix.com/zabbix2.安装zabbix-agent把下载好的rpm安装包拷贝到主机上 运行命令安装rpm -ivh zabbix-agent-3.0.4-1.el7.x86_64.rpm安装完成后设置

編程菜鳥園 2万+

snmp-agent 初步了解

入门级snmp agent开发,通过这篇文章可大致了解snmp agent的开发思路,主要参考了网上博客与官方文档,下方有链接。 用net-snmp扩展MIB库,实现方法可归结为四种: 1)一是静态库方式,通过修改配置头文件,在相应地方包含新引入的mib模块的.c和.h文件,然后重新编译库文件和扩展代码;这种方式不够灵活,每次修改扩展的MIB后,都需要重新编译snmpd和扩展的代码,再...

backkom_jiu的博客 2万+

12c 中Agent问题的描述及解决办法!

问题描述:在另一个节点安装完agent后OMS莫名其妙的down掉。 view sqlnet.log Directory does not exist for read/write [/app/oracle/Middleware/agent/core/12.1.0.1.0/log] [] check the agents logs and find some java exception f...

wangpengfei360 1715
上一篇: hdu1058 Humble Numbers
下一篇: codeforces 676B Pyramid of Glasses 递归
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值