Educational Codeforces Round 44 (Rated for Div. 2) A. Chess Placing

Arduino与Proteus仿真实例-HG7881(L9110)驱动直流电机仿真 HG7881(L9110)驱动直流电机仿真 HG7881 (L9110) 双通道电机驱动器模块。 HG7881 (L9110) 是一款紧凑型电机驱动芯片,支持 2.5-12V 电压范围,800mA 连续电流。 这些芯片具有内置输出钳位二极管以保护敏感的微控制器电子设备。 它们适用于非常小的机器人项目。 每个 HG7881 (L9110) 芯片都能够使用两个数字控制输入驱动单个直流电机。 一个输入用于选择电机方向,而另一个用于控制电机速度。 速度是通过使用 PWM 脉冲宽度调制来控制的。 电机驱动器通常具有 阅读详情

A. Chess Placing
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW".

Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .

In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.

Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).

Input

The first line of the input contains one integer n (2 ≤ n ≤ 100, n is even) — the size of the chessboard.

The second line of the input contains  integer numbers  (1 ≤ pi ≤ n) — initial positions of the pieces. It is guaranteed that all the positions are distinct.

Output

Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.

Examples
input
Copy
6
1 2 6
output
Copy
2
input
Copy
10
1 2 3 4 5
output
Copy
10
Note

In the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.

In the second example the possible strategy is to move  in 4 moves, then  in 3 moves,  in 2 moves and  in 1 move.


题意:给你一个1*n(n偶数)的棋盘,给你n/2个棋子下标,让你把所有棋子全放到奇数位置或全放到偶数位置,棋子平移到相邻位置花费为一,求最小花费。

思路:只可能放到奇数位或偶数位,且一一对应,先排序,分别算两种情况对应位置与排好序的初始下标相减的绝对值之和即为两种情况的最优解,再取min(奇数位花费,偶数位花费)即为答案。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
const int maxn = 105;

int main()
{
        int n, a[maxn], odd = 0, even = 0;
        scanf("%d", &n);
        for (int i = 1; i <= n/2; i ++) {
                scanf("%d", &a[i]);
        }
        sort(a+1, a+n/2+1);
        for (int i = 1, temp = 1; i <= n/2; i ++, temp += 2) {
                odd += abs(a[i] - temp);
                even += abs(a[i] - temp - 1);
        }
        printf("%d\n", min(odd, even));
}




通过 MATLAB/Simulink + Simscape Battery,构建了锂电池老化模型与容量衰减仿真系统 本文基于MATLAB/Simulink平台,构建锂电池老化模型与容量衰减仿真系统,研究储能电池健康管理技术。通过搭建电化学-老化耦合模型,模拟循环和日历老化机制,分析温度、充放电倍率、DOD等因素对电池寿命的影响。系统实现了SOH在线估计和RUL预测功能,仿真了标准日历老化、高倍率循环和峰谷套利等典型工况下的电池衰减行为。结果表明:高温和深充放会显著加速电池老化,而精准的SOH管理可提升储能系统经济性30%以上。文章还探讨了数字孪生、机器学习等高级优化方向,为储能系统长周期运营提供技术支撑。 阅读详情

相关推荐

unity | 动画模块之滚动选项框

动画模块之滚动选项框

菌菌兹的博客 2074

A - Chess Placing CodeForces - 985A

You are given a chessboard of size1 × n. It is guaranteed thatnis even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell c...

280

PicoRV32 笔记 05

PicoRV32 本地总线接口

jjinl的专栏 1573

Educational Codeforces Round 44 (Rated for Div. 2)A. Chess Placing

A. Chess Placingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a chessboard of size 1 × n. It is guaranteed that n is even. The ches...

恒持此志成永志 274

Nginx&&Keepalived(一)Keepalived介绍

一、背景: 案例1:如现有服务my-service-demo,希望实现高可用和负载均衡: 首先,my-service-demo服务部署在两台机器上,通过nginx去代理这两个节点,负载均衡就实现了。如果只有一个nginx,这台nginx机器一旦宕机,访问nginx会报错。这时候在另外一台机器nginx2上也安装nginx,并配置同样的代理,可以解决上述问题,但是暴露给用户的只有一个域名(或ip),不可能给用户提供两个域名,域名1(nginx机器1)访问不了了再让用户访问域名2(nginx机器2),这

w_t_y_y的博客 2880

解密携程风控:user-dun算法中的自定义base64与多模式加密机制剖析

本文深入剖析了携程旅行APP风控核心组件libduncode.so中的user-dun算法。文章重点解密了其采用的自定义Base64编码机制与多模式加密选择逻辑,并详细阐述了如何通过动态分析与静态还原,理解算法与设备指纹的深度绑定关系,为逆向分析类似混淆加固的风控算法提供了系统的方法论。

weixin_29323049的博客 340

CF-Educational Codeforces Round 44 (Rated for Div. 2)-A-Chess Placing

ACM模版 描述 题解 凑等差数列,一种是 a1=1a1=1a_1 = 1,一种是 a1=2a1=2a_1 = 2,取凑成这两种等差数列的代价中较小的,注意序列并没有保证有序,所以需要先排序。 代码 #include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;cmath&gt; using namesp...

逐梦者 740

告别命令行!用这个开源的Web版Kettle工具,5分钟搞定数据集成任务编排

本文介绍了一款开源的Web版Kettle工具,通过直观的拖拽界面大幅提升数据集成效率,告别复杂的命令行操作。该工具基于Kettle核心引擎,支持跨平台协作、轻量化访问和降低学习曲线,特别适合业务分析师快速上手。实测显示,使用该工具后任务配置错误率下降62%,协作效率提升40%。

weixin_30267785的博客 434

Educational Codeforces Round 44 (Rated for Div. 2) C. Liebig's Barrels

题目:http://codeforces.com/contest/985/problem/C 题解:排序后贪心,用小和小的数组一个桶,总之消耗长度小的木板,使得最后的到的和最大 为什么写这个呢,因为我耗费了好长时间找bug,不能将思想准确的表达为代码,还是逻辑思维跟不上写代码速度,写到那儿老想先这样写上,再调着改 #include&lt;bits/stdc++.h&gt; using n...

qq_36386435的博客 288

【Burp入门第三十一篇】Burp+SwitchyOmega实现本地localhost代理

在部分情况下(如本地靶场),当我们需要在Burp中查看、修改本地流量包的时候,按以下三个配置是不能得到本地流量包的。

等风来 3214

第1集:面试官视角:AIOps 核心能力模型与面试项目全局搭建【免费试读】

本文介绍了一门面向AIOps工程师的面试实战课程,针对当前运维领域薪资差距明显的痛点,帮助学员系统掌握企业级AIOps平台开发能力。课程承诺提供可直接用于面试和生产环境的代码实现,从零构建模块化AIOps平台。第一集重点讲解了面试官视角下的核心能力模型,并指导学员搭建项目基础环境,包括Python虚拟环境配置、本地大模型部署(Ollama)以及智能巡检Agent的代码实现。课程强调实战导向,通过40集系统讲解,帮助学员实现薪资40-60万的职业跃升。

qq_2937655951的博客 615

Codeforces Round #442 (Div. 2) A Alex and broken contest

A. Alex and broken contest time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Alex was creating a cont

Star77777的博客 731

Cesium 实现气象(温度,降水,风速)可视化详细代码实现

本教程介绍了使用Cesium实现气象数据可视化的方法,主要包括:1) 搭建Cesium开发环境;2) 三种核心气象要素的展示技术:温度热力图(基于颜色渐变和点密度)、降水区域填充(矩形着色)和风速风向(粒子系统);3) 数据集成方案,包括模拟数据生成和API对接;4) 高级功能如3D温度柱和时间序列动画;5) 性能优化策略,如数据聚合和LOD控制。教程提供了完整的代码示例,从基础配置到视觉效果实现,帮助开发者构建交互式气象可视化应用。

专注AI大模型,软件混淆,授权 1845

Codeforces Round #442 (Div. 2) C - Slava and tanks

C. Slava and tanks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Slava plays his favorite game "Peace Lig

Star77777的博客 615

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Codeforces Round #440 div2 A. Search for Pretty Integers

A. Search for Pretty Integers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given two lists of non

Star77777的博客 544

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Codeforces Round #441 div2 A. Trip For Meal

A. Trip For Mealtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputWinnie-the-Pooh likes honey very much! That is why he decided to visit his friends....

Star77777的博客 534

Codeforces Round #442 (Div. 2) B - Nikita and string

B. Nikita and string time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Nikita found the string contai

Star77777的博客 491

Codeforces Round #440 div2 C. Maximum splitting

C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given several queries. In the

Star77777的博客 488

Codeforces Round #441 div2 B. Divisiblity of Differences

B. Divisiblity of Differences time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output You are given a multiset of n

Star77777的博客 482

Codeforces Round #440 div2 B Maximum of Maximums of Minimums

B. Maximum of Maximums of Minimums time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an array a1

Star77777的博客 480

Educational Codeforces Round 48 (Rated for Div. 2) A. Death Note

http://codeforces.com/contest/1016/problem/A A. Death Note time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You received a notebo...

Star77777的博客 427

Codeforces Round #441 div2 C. Classroom Watch

C. Classroom Watch time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Eighth-grader Vova is on duty today in th

Star77777的博客 419

Codeforces Round #501 (Div. 3) D. Walking Between Houses

http://codeforces.com/contest/1015/problem/D 题意:有n个房子排成一列,编号为1~n,起初你在第1个房子里,现在你要进行k次移动,每次移动一都可以从一个房子i移动到另外一个其他的房子j里(i != j),移动的距离为|j - i|。问你进过k次移动后,移动的总和可以刚好是s吗?若可以则输出YES并依次输出每次到达的房子的编号,否则输出NO。 思路:每...

Star77777的博客 399

Educational Codeforces Round 48 (Rated for Div. 2) B. Segment Occurrences

http://codeforces.com/contest/1016/problem/B 题意:给定两个字符串,若干次询问,问在询问区间内,a中有多少个b (也可用kmp写) 打表 #include &lt;bits/stdc++.h&gt; using namespace std; int a[1100]; int main() { int n,m,k,q,l,r,ans...

Star77777的博客 351

Codeforces Round #502 Div. 1 + Div. 2 B. The Bits

http://codeforces.com/contest/1017/problem/B 题目大意:给出2个二进制的串(数),可以交换第一个串的2个位置,求有多少种交换可以让交换后的第一个串与第二个串异或结果与之前的不同(相同就不算) 思路: 数据范围为10^5,这个二进制数位数最大10^5位,最大值化为十进制2^10^5,不可能枚举 第一个样例:1-&gt;4   3-&gt;2/4/5...

Star77777的博客 338

Codeforces Round #500 (Div. 2) [based on EJOI] C - Photo of The Sky

http://codeforces.com/contest/1013/problem/C 题意:给你2*n个数,让你把其分为两组,一组为x坐标集合,一组为y坐标,将其进行组合为(x,y)坐标,使得所有坐标被一矩形包含,并是该矩形面积最小,输出面积 思路:先排序,面积分两种情况,一种是(a[2 * n - 1] - a[n]) * (a[n - 1] - a[0]),另一种(a[2 * n - ...

Star77777的博客 336

Codeforces Round #500 (Div. 2) [based on EJOI] B - And

http://codeforces.com/contest/1013/problem/B 题意:给出一个数x和n个数,问这n个数能否通过与x进行&amp;操作出现两个相同的数 若能输出最短的变化次数 有这几种情况: 0次:n个数中原本就有相同的数 1次:一个数通过一次变化变成了另一个数 2次:有两个原本不同的数通过各一次变换变成了同一个数 无解:不论如何变换不会出现相同的数 #i...

Star77777的博客 319
上一篇: C++ string中substr用法
下一篇: Educational Codeforces Round 44 (Rated for Div. 2) B. Switches and Lamps
Star77777
博客等级 码龄10年 104粉丝 95原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值