题目链接:http://codeforces.com/problemset/problem/1172/A


题意:一共有2*n张牌,n张0,n张1到n。现在随机的n张(有0有数字)在手上,另n张再牌堆中,现在已知手上的牌和牌堆的牌,可以进行多次以下操作:将手中任意一张牌放入牌堆底,将牌堆顶的一张牌放入手中。问最少多少次后可使牌堆顶到牌堆底的n张牌分别为1,2,3...n。

思路:模拟,判断现有牌堆底能不能继续往下接,例如00123456.不能的话还是等1取出来再往下放。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+;
int vis[maxn];
int a[maxn];
int b[maxn];
int n;
bool check(int b[])
{
int i;
bool flag = true;
for(i = ;i < n;i++)
{
if(b[i] == ) break;
}
if(i == n) return false;
for(i = i + ;i < n;i++)
{
if(b[i] != b[i-] + ) flag = false;
}
return flag;
}
int main()
{
int *it = b;
int t = ;
int ans = ;
bool flag = false;
cin >> n;
for(int i = ;i < n;i++) cin >> a[i],vis[ a[i] ] = ;
for(int i = ;i < n;i++) cin >> b[i];
if(check(b)) t = b[n-] + ,flag = true;
while(t <= n)
{
if(!flag)
{
if(vis[t])
t++;
ans++;
vis[*it]++;
it++;
}
else{
if(vis[t])
t++;
else
{
ans = ;
t = ;
it = b;
for(int i = ;i < n;i++) vis[i] = ;
for(int i = ;i < n;i++) vis[ a[i] ] = ;
flag = false;
continue;
}
ans++;
vis[*it]++;
it++;
} }
cout << ans;
return ;
}

Codeforces 1172A Nauuo and Cards的更多相关文章

  1. code forces 1173 C. Nauuo and Cards

    本文链接:https://www.cnblogs.com/blowhail/p/10990833.html Nauuo and Cards 原题链接:http://codeforces.com/con ...

  2. Codeforces 731 F. Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

  3. Codeforces Round #564 (Div. 2) C. Nauuo and Cards

    链接:https://codeforces.com/contest/1173/problem/C 题意: Nauuo is a girl who loves playing cards. One da ...

  4. Codeforces 387E George and Cards

    George and Cards 我们找到每个要被删的数字左边和右边第一个比它小的没被删的数字的位置.然后从小到大枚举要被删的数, 求答案. #include<bits/stdc++.h> ...

  5. codeforces 140B.New Year Cards 解题报告

    题目链接:http://codeforces.com/problemset/problem/140/B 题目意思:给出 Alexander 和他的 n 个朋友的 preference lists:数字 ...

  6. 【19.05%】【codeforces 731F】 Video Cards

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. Codeforces 1172E Nauuo and ODT [LCT]

    Codeforces ZROI那题是这题删掉修改的弱化版--ZROI还我培训费/px 思路 按照套路,我们考虑每种颜色的贡献,然后发现不包含某种颜色的路径条数更容易数,就是删掉该颜色的点后每个连通块大 ...

  8. Codeforces 1172F Nauuo and Bug [线段树]

    Codeforces 思路 定义\(f_{l,r}(x)\)表示数\(x\)从\(l\)进去\(r\)出来的时候会变成什么样子.容易发现这个函数是个分段函数,每一段都是斜率为1的一次函数,并且段数就是 ...

  9. Codeforces 1173B Nauuo and Chess

    题目链接:http://codeforces.com/problemset/problem/1173/B 思路参考:https://www.cnblogs.com/blowhail/p/1099123 ...

随机推荐

  1. 用 Flask 来写个轻博客 (10) — M(V)C_Jinja 常用过滤器与 Flask 特殊变量及方法

    Blog 项目源码:https://github.com/JmilkFan/JmilkFan-s-Blog 目录 目录 前文列表 Jinja 中常用的过滤器 default float int len ...

  2. scala解析json —— json4s 解析json方法汇总

    使用json4s的框架,包括spark,flink 1.org.json4s 引入pom的方法 对于本地支持,引入以下依赖项添加到pom中 <dependency> <groupId ...

  3. Mybatis缓存1----系统缓存及简单配置介绍

      mybatis缓存 系统缓存:常用的一级缓存和二级缓存 一级缓存 一级缓存是SqlSession级别的缓存,在操作数据库时需要构建SqlSession对象,在对象中有一个数据结构用于存储缓存数据. ...

  4. 14-python基础-列表

    列表常用操作: Ubuntu下进入ipython3中定义一个列表lst=[] 输入lst.TAB ipython会提示列表能够使用的方法. 1.增加列表数据 序号 关键字/函数/方法 说明 1 列表. ...

  5. Maven入门指南11:使用Nexus搭建Maven私服

    1 . 私服简介 私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件.有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库:否则,私服请求外部 ...

  6. LLppdd has a dream!

    LLppdd has a dream Time Limit: 3 s Memory Limit: 256 MB 题目背景 LLppdd经过他充满坎坷的初三后,他的成绩也充满了坎坷. 临近中考了,他希望 ...

  7. 求背景图片左边到#box盒子左边框外侧的距离

    box{ width: 100px; height: 200px; background: pink; padding: 100px; border: 80px solid; background-i ...

  8. 结对编程收获——UI真的没有那么简单

    结对编程收获——UI真的没有那么简单                                                      詹元成 初看作业要求,心里还有一点欣喜,不就是做一个UI ...

  9. 笔记61 Spring Boot快速入门(一)

    IDEA+Spring Boot快速搭建 一.IDEA创建项目 略 项目创建成功后在resources包下,属性文件application.properties中,把数据库连接属性加上,同时可以设置服 ...

  10. 记录常用的linux命令

    原文链接:https://www.cnblogs.com/suger43894/p/11024594.html 系统信息相关 date 显示系统日期 cat /proc/mounts 显示已加载的文件 ...