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. python 内置函数 sorted()

    sorted() 函数对所有可迭代的对象进行排序操作. sort 与 sorted 区别: sort 是应用在 list 上的方法,sorted 可以对所有可迭代的对象进行排序操作. list 的 s ...

  2. 设计模式之Factory(工厂)(转)

    定义:提供创建对象的接口. 为何使用? 工厂模式是我们最常用的模式了,著名的Jive论坛 ,就大量使用了工厂模式,工厂模式在Java程序系统可以说是随处可见. 为什么工厂模式是如此常用?因为工厂模式就 ...

  3. freemark、jsp&css

    **************************************************************freemark相关**************************** ...

  4. Java用Gson按照键值key排序json所有节点

    <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifa ...

  5. itchat key

    http://www.php.cn/python-tutorials-394725.html

  6. Docker学习笔记之docker volume 容器卷的那些事(一)

    预览目录 volume 方式 相关用例 使用方式 使用 volume driver bind mount 方式 相关用例 使用方式 配置selinux标签 配置macOS的安装一致性 tmpfs 方式 ...

  7. JDK源码之HashSet

    1.定义 HashSet继承AbstractSet类,实现Set,Cloneable,Serializable接口.Set 接口是一种不包括重复元素的 Collection,它维持它自己的内部排序,所 ...

  8. PHP 支付类库, cURL开源HTTP类库

    未做任何测试 支付类库地址:http://doc.yurunsoft.com/PaySDK cURL开源HTTP类库地址:http://doc.yurunsoft.com/YurunHttp/1

  9. android之发送Get或Post请求至服务器接口

    import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; imp ...

  10. mvc 前端校验

    首先解决 Ajax.BeginFor异步提交表单,给表单添加样式的问题.不能直接用class属性,网上找了很多都是用ClassName,经过测试不管用,看源代码发现生成的是ClassName而非cla ...