题目链接: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. HDU3450_Counting Sequences

    题意: 让你从所给的序列中找到他的子序列,使他们相邻之间差距不超过d,问有多少个转移的子序列 这题第一眼大概就知道是状态转移,sum[i]表示以前i个中有多少个,那么sum[i+1]比sum[i] 多 ...

  2. 36-python基础-python3-字典与列表的区别

    (1)不像列表,字典中的表项是不排序的.名为 spam 的列表中,第一个表项是 spam[0].但字典中没有“第一个”表项. (2)确定两个列表是否相同时,表项的顺序必须相同,但在字典确定两个字典是否 ...

  3. Install ncurses (ncurses-devel) and try again

    apt install libncurses5-dev libncursesw5-dev

  4. spark on yarn提交任务时报ClosedChannelException解决方案

    spark2.1出来了,想玩玩就搭了个原生的apache集群,但在standalone模式下没有任何问题,基于apache hadoop 2.7.3使用spark on yarn一直报这个错.(Jav ...

  5. read -p 命令--shell 脚本

    #!/bin/bash #This is a Program.it will show your full name. #2019/07/17 fsq PATH=/bin:/sbin:/usr/bin ...

  6. ZedGraph怎样在生成曲线时随机生成不一样的颜色

    场景 在使用ZedGraph生成多条曲线时为了能区分曲线颜色,要求随机设置曲线颜色. 首先从System.Drawing.Color中获取所有颜色的对象的数组,然后将其顺序打乱随机排序,然后在生成曲线 ...

  7. Django之Form操作

    一.Form基础 (一)Form的作用 Django的Form主要有以下几大作用: 生成HTML标签 验证用户数据(显示错误信息) Form提交保留上次提交数据 初始化页面显示数据 (二)实例 一般网 ...

  8. nodejs模块——fs模块 WriteFile写入文件

    WriteFile写入文件 使用fs.writeFile(filename,data,[options],callback)写入内容到文件. 参数说明: filename String 文件名 dat ...

  9. 一只青蛙一次可以跳1阶或者2阶,n阶,有多少种到达终点的方式。

    前两天面试遇到的一个题,当时没有想清楚,今天想了一下,po出来: # -*-encoding:utf-8-*- import sys end = 0 # 终点 cnt = 0 # 统计组合方式 def ...

  10. Vue学习笔记【24】——Vue组件(组件切换)

    使用flag标识符结合v-if和v-else切换组件 页面结构:(缺点:只适用于两个组件间切换,不适合多个)  <div id="app">    <input ...