codeforces round #441 D
来源:互联网 发布:python 交易策略 模拟 编辑:程序博客网 时间:2024/06/05 19:23
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.
给你一列数字a[i]为第i个硬币入列位置
让你求按冒泡排序方法下使序列有序的次数(指标从头到尾算一次)
注意每次硬币入列前的初始状态是没有冒泡过的
我们发现每次冒泡必然会有一个硬币被移到最后面
所以要求的即不在最后面的硬币的个数
由于第i+1次最后面的硬币数不会少于i次
可以通过打tag转移从而避免超时
#include<cstdio>using namespace std;int n,a[300001],f[300001];int main(){scanf("%d",&n);int t=0,x,bj=0;for (int i=1;i<=n;i++){scanf("%d",&x);a[x]=1;int sum=i;if (a[n-bj]==1)while (a[n-bj]==1){bj++;}f[i]=sum+1-bj;}printf("1 ");f[n]=1;for (int i=1;i<=n;i++)printf("%d ",f[i]);return 0;}
- codeforces round #441 D
- Codeforces Round #441 D. Sorting the Coins
- Codeforces Round #441 (Div. 2) D
- Codeforces Round #441 D. Sorting the Coins
- Codeforces Round#213D
- Codeforces Round#131D
- Codeforces Round 341D
- Codeforces Round #428 D
- Codeforces Round #433 D
- CodeForces Round 230 Div2 D
- codeforces div2 round#230 D
- Codeforces Round #270 A~D
- Codeforces Round #317div2 D
- Codeforces Round #339 D. Skills
- codeforces round#377 div2 D
- codeforces Round #382(Div2) D
- Codeforces Round #409 div2 D
- Educational Codeforces Round 21-D
- django redis使用密码
- java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal res
- Editplus使用edTools工具格式化代码后出现乱码的解决方法
- JAVA8的新特性
- AJAX POST请求中参数以form data和request payload形式在servlet中的获取方式
- codeforces round #441 D
- 【个人笔记重点,不作为参考】主题:css垂直居中demo
- 《Effective C++》02总结
- Qt Charts 动态实时折线图绘制
- C#编程入门8_跳转语句
- python保留两位小数:
- offer-35在一个字符串中找到第一个只出现一次的字符
- axios 拦截 , 页面跳转, token 验证(经常用于判断用户是否登录)
- 前端性能优化