CodeForces 875B ( Sorting the Coins) 难度蛮大的一道题目 题目说了一堆主要还是找规律

解题报告(十八)数论题目泛做(Codeforces 难度:2000 ~ 3000 + ) 解题报告(十八)Codeforces - 数学题目泛做(难度:2000 ~ 3000 + ) 阅读详情
                B. Sorting the Coins
            time limit per test: 1 second
            memory limit per test: 512 megabytes
            input: standard input
            output: standard output

Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.

For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:

He looks through all the coins from left to right;
If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.

Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.

The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.

Input
The first line contains single integer n (1 ≤ n ≤ 300 000) — number of coins that Sasha puts behind Dima.

Second line contains n distinct integers p1, p2, …, pn (1 ≤ pi ≤ n) — positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p1, then coin located at position p2 and so on. Coins are numbered from left to right.

Output
Print n + 1 numbers a0, a1, …, an, where a0 is a hardness of ordering at the beginning, a1 is a hardness of ordering after the first replacement and so on.

Examples

input
4
1 3 4 2
output
1 2 3 2 1
input
8
6 8 3 4 7 2 1 5
output
1 2 2 3 4 3 4 5 1

Note
Let’s denote as O coin out of circulation, and as X — coin is circulation.

At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won’t make any exchanges.

After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.

XOOO  →  OOOX

After replacement of the third coin, Dima’s actions look this way:

XOXO  →  OXOX  →  OOXX

After replacement of the fourth coin, Dima’s actions look this way:

XOXX  →  OXXX

Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.


**题意:**题目说了一大堆,有n个硬币,刚开始所有的硬币均为不流通,然后分开n次使得n个硬币流通,小明每次只能从左到右看,若看的位置是流通硬币且下一个硬币是不流通的,则小明则在心中将这两个硬币交换位置,若前后两个硬币均为流通或不流通则不交换,问每次将此时流通的硬币全部排到最后的难度是多少(因为每次看完要记住当前的位置,所以看的次数越多越难,不用看时的难度为1多看一次加一)。其实就是把它移动到最右边
例如 0x0x 意思就是将第一个x右移1位 在1的基础上+1 输出2
**思路:**已经在最后的相连的流通硬币是不会交换的,然后每次将一个流通硬币换到下一个流通硬币时这个流通硬币就不能再换的,要开始换下一个流通硬币,等同于就是每次看把最后的没有在尾部的流通硬币移到尾部,即每次看的次数就是没有连接在尾部的流通硬币个数。难度+1
你只需要把总的x减去最右边连续的x的个数再加1就为答案 n-x+1;


#include <stdio.h>
#include <string.h>
int flag[300001];
int main()
{
    int n,k,m;
    scanf("%d",&n);
    k=n;
    memset(flag,0,sizeof(flag));
    printf("1");
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&m);
        flag[m]=1;
        while(flag[k])
            k--;
        printf(" %d",i+k-n+1);
    }
    puts("");
    return 0;
}
Codeforces算法竞赛代码解析与实战 本文还有配套的精品资源,点击获取 简介:Codeforces是一个深受程序员和算法爱好者喜爱的在线编程竞赛平台。本系列文章将解析Codeforces竞赛中的代码名称及其背后的算法问题。文章将涵盖问题的唯一ID、难度分类以及代码文件的命名规则,同时提供针对不同难度级别(A到G)的问题代码分析。此外,文章还会探讨如何使用C++语言编写高效且功能强大的算法代码,并介绍如何在竞赛中... 阅读详情

相关推荐

UVM验证中,为什么我的pack_bytes()返回长度是0?手把手教你排查自定义do_pack函数

本文深入解析UVM验证中pack_bytes()返回长度为0的常见原因及系统排查方法。从UVM打包机制原理出发,详细列举了super.do_pack()缺失、field automation冲突等典型问题,并提供动态数组处理、位宽计算等进阶调试技巧,帮助开发者快速定位和解决自定义do_pack函数问题。

weixin_42523693的博客 127

信奥入门级相关的比赛(2025.01.13)

信奥入门级相关的比赛(2025.01.13)

青少年趣味编程 3920

超过4.2万个AOI(地理围栏),深圳市2025年2月15日更新的全类别AOI,矢量图层(全国22个超大特大城市AOI更新系列)

超过4.2万个AOI(地理围栏),深圳市2025年2月15日更新的全类别AOI,矢量图层(全国22个超大特大城市AOI更新系列)

1070

coderforce如何上2000分?总结

1. 引言作者分享了自己通过参加Codeforces比赛达到大师级(2426分)的经历,旨在帮助社区成员提升竞赛编程水平。作者将详细解释如何从初学者(1000分)逐步提升到红名选手(2400+分)。作者介绍了几个主要的在线竞赛平台及其结构:作者将提升方法分为多个不同的分数阶段:心理素质在比赛中至关重要。作者建议建立比赛前的固定准备流程,不要在比赛中查看排名,并且要从错误中学习。不要过分担心分数下降,要将每次比赛都视为提升的机会。虚拟比赛是提升能力的关键,主要有两种方式:作者分享了自己成为传奇大师的目标,并介

weixin_59561323的博客 5057

微波无源器件 功分器1 新型方波导双模无功功分器

本名证明了一种基于有着特定功能的(dedicated)T性匹配元件(散射件)的进化结点的新型波导双模两路功分器的可行性。这个散射件,有着面向三个部分的匹配部分,提供了等效功分并且朝着对应的输出端口传输矩形波导的两个TE10/TE01正交模式。所提出的设计紧凑,易于比例变化并且能够级联来获得。

qq_45245770的博客 1390

银河麒麟V10开机卡Logo?别慌,手把手教你进单用户模式修复(附详细命令)

本文详细解析银河麒麟V10操作系统启动时卡Logo的故障原因,并提供进入单用户模式的完整解决方案。通过GRUB引导菜单修改启动参数,执行文件系统检查、图形服务修复等关键命令,帮助用户快速恢复系统正常运行,适用于运维人员和普通用户应对紧急启动问题。

weixin_30522183的博客 391

CodeForces - 875B Sorting the Coins

Sorting the Coins Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having

>*,< 322

Vivado时序违约小结

目录1. setup time违约1.1 逻辑级数太高1.2 Fanout太大2. hold time 违约2.1 异步信号处理导致hold time违约 1. setup time违约 建立时间是工程设计中最常遇到的问题了。一般说来,导致建立时间违例主要有两个原因:逻辑级数太大或者扇出太大,当然也可以尝试通过降频来解决建立时间违约。 1.1 逻辑级数太高 Levels指的是逻辑级数logic level,一个logic level的延迟对应的是一个LUT和一个Net的延迟,对于不同的器件,不同频率的设计能

mu_guang_的博客 7155

codeforces 876B Sorting the Coins

http://www.elijahqi.win/archives/1273 Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins...

Elijahqi 280

通达信源码-主力建仓-AI投研图灵室出品

AI投研图灵室1:=3*SMA((CLOSE-LLV(LOW,75))/(HHV(HIGH,75)-LLV(LOW,75))*100,20,1)-2*SMA(SMA((CLOSE-LLV(LOW,75))/(HHV(HIGH,75)-LLV(LOW,75))*100,20,1),15,1);AI投研图灵室2W:=100-100*(HHV(HIGH,14)-CLOSE)/(HHV(HIGH,14)-LLV(LOW,14));AI投研图灵室3:=SMA(SMA(AI投研图灵室2,3,1),3,1);

qq_57222058的博客 4378

我的宠物狗学编程:从零开始的代码之旅

在这个示例中,我们定义了一个名为"interact"的函数,它通过输入函数获取用户的输入,并根据输入执行相应的代码块。在编程中,我们使用条件语句来根据不同的条件执行不同的代码块。对于我的狗狗,我将创建一个名为"feed"的函数来表示它的进食行为,并根据不同的条件输出不同的信息。在这个示例中,我们定义了一个名为"feed"的函数,并使用一个参数"food"来表示食物。对于我的狗狗,我将创建一个名为"dog_name"的变量来存储它的名字。对于我的狗狗,我将创建一个名为"bark"的函数来表示它的叫声。

2301_79331387的博客 333

Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]

hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该看名字比div2还要简单吧,于是我就做了做....发现确实还蛮简单的hhhh 但是我又突发奇想,干脆更新一篇博客吧,毕竟这也是我少有的能刷完一整套CF的题,那也可以记录一下啦...(虽然div3...

weixin_30900589的博客 1809

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins 乱搞

D. Sorting the Coins time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Recently, Dima met with Sasha in a phil

BlackJack 702

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

CF D. Sorting the Coins

D. Sorting the Coinstime limit per test1 second memory limit per test512 megabytes inputstandard input outputstandard output Recently, Dima met with Sasha in a philatelic store, and since then they

Irish_Moonshine的博客 784

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

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

【Codeforces875B】Sorting the Coins

倒着加就好。#include <bits/stdc++.h> #define gc getchar() #define ll long long #define N 300009 using namespace std; int a[N],Ans[N],n; int read() { int x=1; char ch; while (ch=gc,ch<'0'||ch>'9')

wzf_2000的博客 400

Codeforces Round #441 (Div.2) - D - Sorting the Coins

D. Sorting the Coins time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Recently, Dima met with Sasha in a phil

vloai 901

Sorting the Coins CodeForces - 875B

 Sorting the Coins 题目链接:CodeForces - 875B题意:共有n个硬币, 每次在pi位置放一枚硬币 ,问每次放完硬币后至少需要扫描几次才能确保每个硬币的右侧位置有硬币(发现i位置右边为空则把i位置的硬币右移一个位...

Sirius_han的博客 437

Codeforces875B-Sorting the Coins

Sorting the Coins Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sash

Mi-Queen 524

Codeforces - 图论题目(难度:2200)

Codeforces - 图论题目(难度:2200) AC 之后不写题解,赛前火葬场!! 1. 507E - Breaking Good(最短路 + 松弛条件改造) 题目链接:https://codeforces.com/contest/507/problem/E 1.1 题意 给你一个 n(2≤n≤105)n(2 \le n\le 10^5)n(2≤n≤105) 个点和 m(0≤m≤min⁡(n...

Nitrogens的博客 1663

记第一次打codeforces

昨天第一次打cf,虽然我的账号申请很长时间了,但是暑假一直在玩多校,然后被多校玩了一把,真爽。说实话,我现在真的很喜欢这种比赛,发自内心,有点困了,昨天打了一小时,看着ac了两道就关机了,其实有一道后来被hack了 然后因为我读题失误,造成了严重的掉分。3,4天一次的cf只要不是10:50的我以后必参加,我要开始上分了,上钻石,上大师。(梦想还是要有的) 今天做了一下昨天的题,我认为,我最多做

但求心安的博客 4374

全世界最强的算法平台codeforces究竟有什么魅力?

大家好,之前说过由于和LeetCode结了梁子,所以周末的LeetCode专题取消了,给大家写点其他专题的算法问题。目前选择的是国外著名的编程竞赛平台——codeforces。它在竞赛圈名气比较大,对于普通大学生而言可能了解不多。所以今天这篇文章简单和大家介绍一下codeforces这个网站,以及它的使用方法。 链接:codeforces.com codeforces简介 简单介绍一下codeforces这个网站,codeforces位于宇宙编程最强的毛国。据说最早是由俄罗斯的一群大学生维护的,它最大的特点

TechFlow的博客 3万+

codeforce Sorting the Coins

其实这个题看明白了挺简单的。 题目大意: 给你n个不流通的硬币,然后每次替换其中一个,每替换一个就询问一次按照Dima的算法需要几次才能最终没有可以相互交换的coin。 每次替换之后,按照Dima的算法执行时,coin的顺序是不变的,因为题目中说了DIma只可以在心中想,不可以移动coin。 题解:首先要想明白每次执行Dima的算法都会把一个不流通的coin移动到最后面,所以题目就变成了每次...

羽翼的博客 354

Sorting the Coins(思维)

Sorting the Coins Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite...

codeswarrior的博客 425

Codeforces 875B Sorting the Coins

题意实在难秒速,多看看原题应该能看懂- -。。。 题解: 容易知道规律,对于这个数列中假如有x个in circulation的数字,那么结果就是x+1(其中不包括从右端点开始连续的in circulation的数) 例如:(O表示out of circulation,X表示in circulation) OOXXOO  结果是3 OOXOXX  结果是2 OXXOOX  结果是

weixin_36796040的博客 1064

Codeforces 876 D. Sorting the Coins 模拟

题意给出n(300000),最初状态表示n个0. 然后给出n个数,表示依次把ai位置置为1. 输出最初和每次变换后的扫描次数. 扫描次数为除了末尾连续的1之外1的个数+1.解法一个变量last记录末尾有几个连续的1,ans=i-last+1. 每次置换时,倒序扫描,总扫描次数不会超过n,可行.其他比赛时抽风,居然模拟链表……代码/* LittleFall : Hello! */ #inclu

秋叶红于二月花 845
上一篇: CodeForces 844A Diversity (超级超级水唯一需要想得就是开个标记数组吧)
下一篇: 给你N个数求其最小公倍数(hdu 1019 Least Common Multiple)
Puppet__
博客等级 码龄9年 319粉丝 328原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值