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. PHP5.4以下的json_encode中文被转码的问题

    PHP的json_encode中文被转码的问题   在php5.2中做json_encode的时候.中文会被unicode编码, php5.3加入了options参数, 5.4以后才加入JSON_UN ...

  2. python之auto鼠标/键盘事件

    mouse_key.py import os import time import win32gui import win32api import win32con from ctypes impor ...

  3. layui使用iconfont

    layui的图标取自于阿里巴巴的矢量图标库 Iconfont,同样的,这篇教程也是基于Iconfont进行扩展. 第一步,通过浏览器打开 http://iconfont.cn/ ,访问阿里巴巴矢量图标 ...

  4. Jira客户端

    github地址 https://github.com/rcarz/jira-client 使用 1)私服 <!-- https://mvnrepository.com/artifact/net ...

  5. sqlloader parallel调用报ORA-26002: table has index defined upon it.解决方法

    ORA-26002: table has index defined upon it. This issue is caused when using the bulk load option in ...

  6. 关于er模型中的identifying relationship or non-identifying relationship

    最近,主要负责项目管理和领域模型设计方面的工作,昨天在将UML类图转换为ER模型的时候,发现有identifying relationship or non-identifying relations ...

  7. java中线程的停止以及LockSupport工具类

    看jstack输出的时候,可以发现很多状态都是TIMED_WAITING(parking),如下所示: "http-bio-8080-exec-16" #70 daemon pri ...

  8. Oracle Redo log 状态及工作原理解析

    Oracle重做日志(redo log)是用来记录操作条目,用于数据库数据恢复.为了提高效率,oracle通常建议设置三组redo log.本文将对重做日志组的状态以及多种状态之间切换做解析,力求掌握 ...

  9. opencv学习之路(12)、图像滤波

    一.图像滤波简介 二.方框滤波——boxFilter() #include<opencv2/opencv.hpp> using namespace cv; void main(){ Mat ...

  10. Ubuntu软件操作的相关命令

    Ubuntu软件操作的相关命令 sudo apt-get update ------------------------------- 更新源 sudo apt-get install package ...