http://codeforces.com/contest/876/problem/D

题意:
题意真是难懂,就是给一串序列,第i次操作会在p[x](1<=x<=i)这些位置放上硬币,然后从左到右观察,如果第i个位置有硬币但第i+1个位置没有硬币,那么互换,然后继续从第i+1个硬币开始看。直到不需要交换,需要计算出到终极状态需要多少步。

思路:

模拟。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = +; int n;
int p[maxn];
int a[maxn];
vector<int> ans; int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d",&n))
{
ans.clear();
memset(a,,sizeof(a));
for(int i=;i<=n;i++) scanf("%d",&p[i]);
int max_right=n;
int cnt=;
for(int i=;i<=n;i++)
{
a[p[i]]=;
if(p[i]==max_right)
{
for(int j=max_right-;j>=;j--)
{
if(!a[j]) {max_right=j;break;}
else cnt--;
}
}
else
{
cnt++;
}
ans.push_back(cnt+);
}
printf("");
for(int i=;i<ans.size();i++)
printf(" %d",ans[i]);
printf("\n");
}
return ;
}

Codeforces Round #441 D. Sorting the Coins(模拟)的更多相关文章

  1. Codeforces Round #441 (Div. 2)【A、B、C、D】

    Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...

  2. Codeforces Round #441 (Div. 2)

    Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...

  3. [日常] Codeforces Round #441 Div.2 实况

    上次打了一发 Round #440 Div.2 结果被垃圾交互器卡掉 $200$ Rating后心情复杂... 然后立了个 Round #441 要翻上蓝的flag QAQ 晚饭回来就开始搞事情, 大 ...

  4. ACM-ICPC (10/16) Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)

    A. Trip For Meal Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. ...

  5. Codeforces Round #441 Div. 2 A B C D

    题目链接 A. Trip for Meal 题意 三个点之间两两有路径,分别长为\(a,b,c\),现在从第一个点出发,走\(n-1\)条边,问总路径最小值. 思路 记起始点相邻的边为\(a,b\), ...

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

    http://codeforces.com/contest/876/problem/D 题意: 最开始有一串全部由"O"组成的字符串,现在给出n个数字,指的是每次把位置n上的&qu ...

  7. codeforces Round #441 A Trip For Meal【思路/模拟】

    A. Trip For Meal time limit per test 1 second memory limit per test 512 megabytes input standard inp ...

  8. Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)

    A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  9. Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

随机推荐

  1. ATM取款机

    package Tests; import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;impo ...

  2. 外网上传到NAS速度很慢是什么情况?上行1M都不到,但是测试有4M

    外网上传到NAS速度很慢是什么情况?上行1M都不到,但是测试有4M NAS可以将自己的影片,图片,音乐都放在NAS中.在家中就能无线共享了.在其他地方要下载自己nas里的影片,下载速度主要取决于家里宽 ...

  3. [转载] Oracle之内存结构(SGA、PGA)

    2011-05-10 14:57:53 分类: Linux 一.内存结构 SGA(System Global Area):由所有服务进程和后台进程共享: PGA(Program Global Area ...

  4. scanf,fscanf,sscanf的区别

    scanf是从文件中读 sscanf是从字符串中读 scanf是从键盘输入中读   fread :以字节位计算长度,按照指定的长度和次数读取数据,遇到结尾或完成指定长度读取后停止.fscanf :格式 ...

  5. git 新建本地分支后将本地分支推送到远程库, 使用git pull 或者 git push 的时候报错

    是因为本地分支和远程分支没有建立联系  (使用git branch -vv  可以查看本地分支和远程分支的关联关系)  .根据命令行提示只需要执行以下命令即可git branch --set-upst ...

  6. Mongo第三个参数的用法

    Mongo update的用法 Update( array $criteria , array $new_object [, array $options = array() ] ) 第一个参数是条件 ...

  7. Python3 解析XML 层序遍历二叉树

    Python3 解析XML 层序遍历二叉树 keyword : python3, xml, xml.dom.minidom, 层序遍历, 层次遍历, 二叉树 part1 问题描述 面对如下 XML 文 ...

  8. nvdimm

    https://www.jianshu.com/p/2c0d797fdcc5 https://www.suse.com/c/nvdimm-enabling-suse-linux-enterprise- ...

  9. amqp 抓包

    1. wireshark 2. tcpick -yR -r  file.name

  10. php 操作 mysql 数据库常用方法集合

    参考: https://www.runoob.com/php/php-pdo.html https://www.cnblogs.com/feng18/p/6523646.html https://bl ...