题目链接: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. PHP的安装配置

    一.安装 PHP的安装可以很简单的使用yum命令进行安装. #添加php7.0源(这是centos7的命令,centos6.5的命令不同,不要照搬)rpm -Uvh https://dl.fedora ...

  2. PHP中使用raw格式发送POST请求

    如果请求的参数格式是原生(raw)的内容,应该如何为程序构造一个POST请求函数呢? function http_post($url, $data_string) { $ch = curl_init( ...

  3. Java实验报告(三)&第五周课程总结

    班级 计科二班 学号 20188425 姓名 IM 完成时间2019/9/27 评分等级 实验三 String类的应用 实验目的 掌握类String类的使用: 学会使用JDK帮助文档: 实验内容 1. ...

  4. Spring Cloud配置中心内容加密

    从配置获取的配置默认是明文的,有些像数据源这样的配置需要加密的话,需要对配置中心进行加密处理. 下面使用对称性加密来加密配置,需要配置一个密钥,当然也可以使用RSA非对称性加密,但对称加密比较方便也够 ...

  5. Spring Cloud Eureka自我保护机制

    自我保护背景 首先对Eureka注册中心需要了解的是Eureka各个节点都是平等的,没有ZK中角色的概念, 即使N-1个节点挂掉也不会影响其他节点的正常运行. 默认情况下,如果Eureka Serve ...

  6. Python列表推导式中使用if-else

    data_list=[] col=["a", "b", "c", "d"] jdata={"a":1 ...

  7. React-Native 使用中的坑

    android 1.键盘会在 ScrollView 之上----不知道是不是未给ScrollView 设置高度的问题 2.navigation的标题在android居中显示办法 navigationO ...

  8. LeetCode Array Easy 27. Remove Element 解题

    Given an array nums and a value val, remove all instances of that value in-place and return the new ...

  9. Activiti学习笔记3 — 流程定义

    一.创建流程引擎对象 private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); 二.发布一个流程 ...

  10. wdcp后台登陆访问失败处理方法

    用putty或xsheel链接 进入之后输入命令 service wdcp restart 之后显示ok就成功了