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

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

思路:

模拟。

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<vector>
 6 #include<stack>
 7 #include<queue>
 8 #include<cmath>
 9 #include<map>
10 #include<set>
11 using namespace std;
12 typedef long long ll;
13 typedef pair<int,int> pll;
14 const int INF = 0x3f3f3f3f;
15 const int maxn = 300000+5;
16
17 int n;
18 int p[maxn];
19 int a[maxn];
20 vector<int> ans;
21
22 int main()
23 {
24     //freopen("in.txt","r",stdin);
25     while(~scanf("%d",&n))
26     {
27         ans.clear();
28         memset(a,0,sizeof(a));
29         for(int i=1;i<=n;i++) scanf("%d",&p[i]);
30         int max_right=n;
31         int cnt=0;
32         for(int i=1;i<=n;i++)
33         {
34             a[p[i]]=1;
35             if(p[i]==max_right)
36             {
37                 for(int j=max_right-1;j>=1;j--)
38                 {
39                     if(!a[j])  {max_right=j;break;}
40                     else cnt--;
41                 }
42             }
43             else
44             {
45                 cnt++;
46             }
47             ans.push_back(cnt+1);
48         }
49         printf("1");
50         for(int i=0;i<ans.size();i++)
51             printf(" %d",ans[i]);
52         printf("\n");
53     }
54     return 0;
55 }

转载于:https://www.cnblogs.com/zyb993963526/p/7679291.html

Codeforces Round #441 D. Sorting the Coins(模拟)相关推荐

  1. Codeforces Round #441 Div. 2题解

    A.直接判断相邻的边是不是最短边 是就来回走 不然就走一条第二的然后再来回走 #include<cstdio> #include<cstring> #include<al ...

  2. Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟

    A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-t ...

  3. Codeforces Round #552 (Div. 3) E stl模拟 F dp G gcd

    contest链接 https://codeforces.com/contest/1154 E 题解思路 直接哈希模拟删除T了,可以用setsetset和lowerlowerlower_boundbo ...

  4. Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)

    A题:一个三角形,一开始在C点,给边长a,b,c问上面走n-1次走多少步. ???为什么会写错??? #include<stdio.h> #include<string.h> ...

  5. Codeforces Round #494 (Div. 3) D. Coins and Queries(贪心

    题目链接 题目大意:给你n个物品,第iii个物品价值aia_iai​,询问q次,问你能不能凑出价值为qiq_iqi​的物品. 小贪心吧.从大到小找,能拿就拿就行了. #include<bits/ ...

  6. Codeforces Round #176 (Div. 2) D. Shifting(模拟,STLdeque应用)

    题目链接 D. Shifting time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  7. Codeforces Round #441 (Div. 1, by Moscow Team Olympiad) C. National Property CF875C

    其实就是检查第i 跟 i+1 序列是否合法 合法就不理它 如果不合法再变一下 最后再拓补检查一下构造出的解是否合法 #include <iostream> #include <alg ...

  8. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C 1 /* 2 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 3 模拟题:蛮恶心的 ...

  9. 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie

    题目传送门 1 /* 2 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 3 题目倒是很长:) 4 */ 5 #include <cstdio> 6 #include <al ...

最新文章

  1. 搜狗词库爬虫(2):基础爬虫框架的运行流程
  2. django23:BS4/kindeditor上传图片
  3. (计算机组成原理)第五章中央处理器-第五节1:指令流水线(定义和表示方法及性能指标)
  4. ospf避免环路_路由环路知识点总结!
  5. Symfony 框架实战教程——第一天:创建项目(转)
  6. 【距离GDOI:136天】 后缀数组中...
  7. 06-多进程之间通过Queue来实现数据共享学习笔记
  8. SketchUp插件|ClothWorks布料模拟 免费下载!(草图大师制作窗帘张拉膜等)
  9. fritzing元件太少_Arduino电路设计软件Fritzing
  10. aws linux vps使用教程,亚马逊云(AWS)注册账号和启动服务器EC2(centos镜像)教程(踩坑记)...
  11. 罗马数字转整数(C++)
  12. WebBowser 实现淘宝网自动登录
  13. busybox文件系统制作
  14. Xftp 7(FTP/SFTP客户端) V7.0.0107 官方中文免费正式版(附文件+安装教程)
  15. Java每日一题——>19. 删除链表的倒数第 N 个结点
  16. 深度学习准备之安装双系统
  17. 企业破产重整网_全国企业破产重整案件信息网今天正式上线开通
  18. 达观杯数据竞赛 -- LR+SVM处理词向量特征
  19. Tomoya【省选模拟赛】
  20. 物联网之场景联动策略

热门文章

  1. [Flexbox] Using order to rearrange flexbox children
  2. 中科燕园arcgis外包----排水管网地理信息系统
  3. 射击的乐趣:WIN32诠释打飞机游戏
  4. Android数据的四种存储方式SharedPreferences、SQLite、Content Provider和File (二) —— SQLite...
  5. PDU (Protocol Data Unit) - 协议数据单元
  6. 基于GCCAVR的TLC2543读写程序----模拟SPI方式实现
  7. centeros7安装mysql - 风中追风_lonely - 博客园
  8. Class.getResource和ClassLoader.getResource
  9. koa --- jwt实现最简单的Token认证
  10. Linux基础命令---su 1