Codeforces Round #740 (Div. 2) B. Charmed by the Game

别再为PT100测温发愁了!手把手教你用ADS1247+STM32搞定高精度温度采集(附完整代码) 本文详细介绍了如何使用ADS1247与STM32构建高精度PT100测温系统,涵盖硬件设计、SPI配置、温度计算及调试技巧。通过24位ADC和内置PGA,实现0.1℃级精度,适用于工业自动化和医疗设备。附完整代码和常见问题解决方案,助你快速掌握高精度温度采集技术。 阅读详情

题目大意

两个人在打网球,两人轮流发球,有两种得分的情况,一个是自己发球的回合得分,叫做"holds",另一种是在对方发球的回合得分,叫做"breaks",现在给出比赛结束后两个人的得分,问你两个人总的"breaks"的次数有多少种情况。我们是不知道谁先发球,而且每一回合谁得分的,只知道两个人的最后得分。

思路

分两种情况,总的比赛回合sum为奇数或为偶数两种:
偶数比较好懂,先说偶数:

sum为偶数:
可以确定两个人发球的次数是相同的,所以谁先发球是不影响最后的答案的。

我们以分数少的人来看看,假设是a,得分为minp,另一个是b,那么minp肯定是小于等于sum / 2的,在a的sum / 2次发球回合中,我们假设他的发球得分次数即"holds"的次数为i(0 <= i <= minp),那么a需要从b那里"breaks"的次数为minp - i,而a的发球没有得分的次数就是被b"breaks"的次数,为sum / 2 - i,
所以总的"breaks"的次数为sum / 2 - i + minp - i,直接枚举i即可得到答案。

sum为奇数:
其实奇数的情况跟偶数是类似的,只是对于a来说,他有两种发球个数的情况,一个是sum / 2,一个是sum / 2 + 1,所以在枚举i的时候直接多一种答案的可能,即多一个sum / 2 + 1 - i + minp - i即可。
这里可能有人觉得会同一种情况重复出现两次,但是仔细看上面的式子,它是减掉两次i的,所以sum / 2 + 1 - i + minp - i相当于两个相邻的sum / 2 - i + minp - i中间的一个数也是满足题意的。

用一个vector存所有可能,答案就出来了。

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        int sum = a + b;
        vector<int> ans;
        if(sum & 1) // 总的回合为奇数
        {
            int minp = min(a, b);
            for(int i = minp; i >= 0; i--)
            {
                ans.push_back(sum / 2 - i + minp - i);
                ans.push_back(sum / 2 + 1 - i + minp - i);
            }
        }
        else // 总的回合为偶数
        {
            int minp = min(a, b);
            for(int i = minp; i >= 0; i--)
            {
                ans.push_back(sum / 2 - i + minp - i);
            }
        }
        printf("%d\n", ans.size());
        for(auto i: ans)
        {
            printf("%d ", i);
        }
        puts("");
    }
    return 0;
}
HDMI接口及其在编程中的应用 在编程中,我们可以使用HDMI接口来控制和管理连接到计算机的HDMI设备。本文将介绍HDMI接口的基本原理以及如何在编程中使用HDMI接口。在编程中,我们可以使用HDMI接口来控制和管理连接到计算机的HDMI设备。本文介绍了HDMI接口的基本原理,并提供了使用Python编程语言和相关库实现HDMI接口应用的示例代码。我们可以使用编程语言提供的音频库来生成和播放音频,并将其通过HDMI接口输出到连接的设备上。我们可以使用编程语言提供的音频库来生成和播放音频,并将其通过HDMI接口输出到连接的设备上。 阅读详情

相关推荐

Maltab GUI课程设计——网络爬虫程序(基金连涨连跌提醒)

Maltab GUI课程设计——网络爬虫程序(基金连涨连跌提醒)

果果爱腰果的博客 849

Codeforces Round #740 (Div. 2) F. Top-Notch Insertions 线段树 / 平衡树 + 组合数学

传送门 文章目录题意:思路: 题意: 思路: 考虑最终的序列是什么鸭子的,首先序列肯定单调不降,也就是a1≤a2≤a3≤...≤ana_1\le a_2\le a_3\le ...\le a_na1​≤a2​≤a3​≤...≤an​,显然不可能都是$\le 号,因为如果插入的话是有可能产生号,因为如果插入的话是有可能产生号,因为如果插入的话是有可能产生<号的。假设我们现在有号的。假设我们现在有号的。假设我们现在有x个个个<$ 号,那么应该有(n+n−1−xn)\binom{n+n-1-x}{n}

m0_51068403的博客 433

从亚稳态到稳定传输:深入解析CDC跨时钟域同步的核心技术与设计实践

本文深入解析了CDC(跨时钟域同步)技术的核心问题与解决方案,重点探讨了亚稳态现象及其危害,详细介绍了同步器设计、MTBF计算方法以及单bit和多bit信号同步的实战技巧。通过Verilog代码示例和工程实践案例,帮助读者掌握从亚稳态到稳定传输的关键技术,提升数字电路设计的可靠性。

weixin_32822843的博客 246

Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))

Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))(https://codeforces.com/contest/1561) 一边被折磨一边打代码 A. Simply Strange Sort (https://codeforces.com/contest/1561/problem/A) You have a permutation: an array a=[a1,a2,…,an] of distinct integer

好好好,这么写博客是吧 479

手把手拆解:储能电站如何实现‘孤岛运行’与‘黑启动’?从SVPWM控制到无缝并网

本文深入解析储能电站的孤岛运行与黑启动技术,从SVPWM控制策略到电网重构实战。通过详细的三环控制架构和黑启动五阶段技术路线,展示储能电站在电网故障时如何快速切换为独立电压源并实现电网重建。文章还探讨了虚拟惯量补偿、多站协同控制等前沿技术,为电力系统应急恢复提供关键解决方案。

weixin_30509393的博客 304

脑电分析:为什么大脑信号会“变同步”?——事件相关同步化与去同步化 (ERS/ERD) 全景解析

脑电分析中的事件相关同步化(ERS)和去同步化(ERD)是研究大脑动态节律的重要方法,反映特定任务下脑电频段能量的变化。ERD表示神经元活动分散(功率下降),提示脑区活跃处理信息;ERS则反映神经元同步(功率增强),常与静息状态相关。本文详解了ERS/ERD的生理机制、计算流程(包括基线校正和功率谱分析),并提供了Python实现示例,展示如何通过Welch法和STFT进行时频分析,生成ERD/ERS热力图。该技术广泛应用于运动想象脑机接口、癫痫检测等领域,为理解大脑功能状态提供了量化工具。

qq_32516809的博客 1394

Codeforces1561B Charmed by the Game (思维)

题目链接: Charmed by the Game 大致题意 A和B玩一个游戏, 两个人轮流发球(最初时, 可以A先发, 也可以B先发). 如果A发球, B接住了, 称为"破发", 反之依然. 如果A发球, B没接住, A赢. 若B接住了, B赢. 反之依然. 现给出A和B胜利的次数, 问可能出现的破发情况有多少种, 并输出每种情况下的破发次数. 解题思路 思维 (感觉这个题思维量真的高) 首先我们考虑, 其实发球情况只有两种, 一种是A先手, 另外一种是B先手. 我们不妨讨论A先手发球的情况, 另外一种

Fau的博客 396

Tessent MBIST SDC

主要是两个PROC,tessent_constrain_${design_name}_mentor_ijtag_non_modal和tessent_constrain_${design_name}_mentor_memory_bist_modal。其中,Memory/MBIST controller/MEM Interface可以从func_clk_1来(用func_clk_1和func_clk_2的高频时钟),如图中红色线。其中,SIB和BAP用ijtag_tck的clock,如图绿色线。

po_poo的博客 1988

B. Charmed by the Game

原题 思路 一个人只有先发后接或者先接后发两种情况,也对应另外一个人的两种情况 所以只需要考虑其中一个人(称作小明)的两种情况即可 对于小明来说他发球的次数有q1 = (a + b) / 2 与 q2 = a + b - q1两种 设他发球赢了i次则接球(即打破对方接球)a - i次 在他发球输了q - i次即被对方打破q - i 次 两种情况均遍历一遍即可得到结果 选用了内置排序与去重的set<>容器 代码 #include<bits/stdc++.h> using

m0_60610120的博客 646

FLUX.1 LoRa 微调

微调的好处:可以让你突破换脸这种输入图片的场景约束,微调好的模型可以让你真正的文生图。换脸只能根据输入的图片和视频来生成内容。

szmars的博客 3621

彻底解决Win11锁屏界面黑屏或者图片不变化

windows锁屏后黑屏

renkai721的专栏 1万+

B. Charmed by the Game(思维题tql)

B. Charmed by the Game 其位分为发球和接球两种轮流的游戏 设第一个人赢了a,第二个人赢了b次。 x,y为两人可能的两种发球次数 x=a+b>>1 y=a+b-x 以下为对于第一个人考虑的情况: 也就是说第一个可能发x次球的情况下赢了a个球或发y次球的情况下赢了a个球。 对于一种发球次数x,枚举第一个人在发球时赢得个数i, 则第一个人的a,由发球时赢得i次,和接球时赢得a-i次构成。 发球时赢得次数不超过发球次数x,接球时赢得次数不超过接球次数也就是其二个人发球次数y 即

qq_53126117的博客 455

YOLO26改进策略【卷积层】| HWD,引入`Haar小波变换`到下采样模块中,减少信息丢失

本文记录的是。传统的卷积神经网络中常用的最大池化平均池化和步长为2的卷积等操作进行下采样可能会导致信息丢失,为了解决信息丢失问题,HWD作者受无损信息变换方法的启发,引入Haar小波变换到下采样模块中,

Limiiiing的博客 346

Codeforces Round #740 (Div. 2, based on VK Cup 2021 - Final (Engine))B. Charmed by the Game 题解

题目大意 AliceAliceAlice和BobBobBob打球,两个人轮流发球。每一轮以某一方胜利宣告结束。接球方胜利,则称为“打破发球”;发球方胜利,则称为“保持发球”。 已知AliceAliceAlice赢了aaa轮,BobBobBob赢了bbb轮,但不清楚谁先发球,也不清楚谁赢了哪轮游戏。让kkk表示“打破发球”的次数,现在请你求出kkk的所有可能取值。 输入描述 每次测试包含多组测试用例。 第一行一个t(1≤t≤103)t(1≤t≤10^3)t(1≤t≤103)表示测试用例的数目,接下来t行每行一

keguaiguai的博客 190

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

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

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

CF1558A Charmed by the Game-Codeforces Round #740 (Div. 1, based on VK Cup 2021 - Final (Engine))

原文链接Dashboard - Codeforces Round #740 (Div. 1, based on VK Cup 2021 - Final (Engine)) - Codeforces 制作不易,点个赞再走 题目描述 Alice and Borys are playing tennis. A tennis match consists of games. In each game, one of the players is serving and the other one is re

jisuanji2606414的博客 421

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Codeforces Round #740 (Div. 2) B C

B. Charmed by the Game 题目大意: A和B轮流发球,给出A和B的胜利场数a和b,但是不知道谁先发球,问最后破发球次数的所有可能。接球一方胜利即为破发球。 题解: 因为不知道谁先发球,所以可以分为两种情况, 一种为A先发球,另一种为B先发球 每个人发球的次数很容易得出来,定义x = (a + b) / 2,y = a + b - x 那么A要么发球x次,要么发球y次。 A发球x次:若A在发球中胜利i次,那么A就有a - i次破发球,B就有x - i破发球,a - i + x - i即为总

weixin_52278699的博客 216

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

codeforces740D

Codeforces 740D Alyona and a tree 二分+树上差分

清澈不在远方 554

Charmed by the Game(思维)

题目 Charmed by the Game 问题描述 大意是有A、B两个人轮流发球(不会因为胜负情况而改变顺序),在每局游戏中,若发球方胜利则被称该玩家保持了发球(但不会影响发球权的交替),若接球方胜利则称该玩家打破了发球。 每次会给定A,B分别的获胜次数a,b(不存在平局的情况),问总共可能出现过几次玩家打破发球的情况。 分析 int x=(a+b)/2; int y=a+b-x; 由于发球权是不断交替的,所以对于玩家A来说,发球的次数要么为x次,要么为y次。 当发球次数为x次时,已知A获胜了

qq_52441682的博客 797

codeforces round#740

A. Simply Strange Sort 数据规模不大,可以直接模拟 #include<bits/stdc++.h> using namespace std; #define N 6010 int a[1010]; int n; typedef long long ll;const ll mol=1e9+7; int check(){ for( int i=1;i<=n;i++){ if(a[i]!=i) return 0; } return 1; } int main(){

qq_41729237的博客 255

Codeforces Round #703 (Div. 2) (自闭场)

A. Shifting Stacks 这题我能记很久,直接给我打自闭了,从开赛一直到了最后,我就一个菜鸡 题意非常简单,给你n个数,让你把他们构造成递增的,然后只能从后往前,你直接想就行了,直接构造0 1 2 3 4 5 6 7 8 9…n如果可以的话,就是yes,不可以的话就是no 然后上我第一遍的代码 #include <bits/stdc++.h> #define int long long #define BUFF ios::sync_with_stdio(false), cin.t

godhandsjoker的博客 2658

Codeforces Round #740(Div. 2)部分题解

A 点击此处查看对应的题目. 本题模拟 本题要求最后迭代完成的数组必须递增,那么,首先检验是否符合这个条件,如果不符合就反复迭代。 按题意来说,迭代的过程需要按奇数和偶数进行枚举不符合条件则与后一个数交换。反复迭代后记录其次数便是答案。 时间复杂度 O(n3)O(n^3)O(n3) #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1010,INF = 1e9 + 5; int a[N

山中一扶苏的博客 202

Codeforces Round #381 (Div. 2) &&Codeforce_740

A. Alyona and copybooks水题,让求满足条件的最小花费,注意组合可能是多个即可。#include <bits/stdc++.h> using namespace std;typedef long long ll;int main(int argc, char const *argv[]) { ll n,a,b,c; cin>>n>>a>>b>>c; n%=

坚持不懈 694

codeforces 1556B Take Your Places!

链接: https://codeforces.com/problemset/problem/1556/B 题意: 给n个数,可以交换相邻的两个数,问最少通过几次交换,可以把这串数字变成奇偶交替的形式,如果不能输出-1。 本题可以分四种情况讨论 1.两种数字(奇数和偶数)数量相差大于1,一定不能变成; 2.两种数字数量相同,计算两种数字打头,需要交换的次数取最小值; 3.奇数比偶数多1,交换的次数就是奇数打头时,需要交换的次数; 4.偶数比奇数多1,与3同理。 我们在计算需要交换的次数时,其实只需计

qq_58756335的博客 427

B. Take Your Places!(Codeforces)

先判断奇数和偶数的个数情况: if(n==1) 则不用处理,输出0 else if(奇数和偶数的个数相差大于1)则不存在符合条件的序列,输出-1 else if(奇数的个数大于偶数的个数)只能奇数放在第一个进行排列 else if(偶数的个数大于奇数的个数) 只能偶数放在第一个进行排列 else if(奇数和偶数的个数相等) 奇数放在第一个和偶数放在第一个取最小 完整代码如下: #include<iostream> #include<vector> #include<cm..

daq0411的博客 422

2021暑假集训-个人赛11

文章目录A.Simply Strange SortB.Charmed by the Game *C.Deep Down BelowD.Up the Strip (simplified version) *E.Up the Strip *F.Bottom-Tier Reversals *G.Top-Notch Insertions * A.Simply Strange Sort 传送门 题目大意:有两种操作,一种是偶数只对偶数和他后面的进行判断,如果前面大,前后就进行交换 ,同理奇数也是这样,奇数跟偶数..

xingzi201的博客 422

Codeforces Round #740 (Div. 2) E. Bottom-Tier Reversals 构造

传送门 文章目录题意:思路: 题意: 给你一个长度为奇数nnn的排列aaa,每次可以选择长度为奇数的前缀,并将[1,len][1,len][1,len]翻转,你需要用不超过5n2\frac{5n}{2}25n​次操作将其变成有序的,输出方案。 如果无解输出−1-1−1。 n≤2021n\le2021n≤2021,nnn是奇数 思路: 比较套路的构造吧,没做血亏。 首先不难发现,翻转不会改变位置的奇偶性,所以如果i mod 2!=ai mod 2i\bmod2!=a_i\bmod2imod2!=ai​mod2

m0_51068403的博客 201
下一篇: AtCoder Beginner Contest 216 D - Pair of Balls(搜索)
路过放个屁
博客等级 码龄6年 1粉丝 13原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值