Codeforces 1172A Nauuo and Cards
题目链接: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的更多相关文章
- code forces 1173 C. Nauuo and Cards
本文链接:https://www.cnblogs.com/blowhail/p/10990833.html Nauuo and Cards 原题链接:http://codeforces.com/con ...
- Codeforces 731 F. Video Cards(前缀和)
Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...
- 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 ...
- Codeforces 387E George and Cards
George and Cards 我们找到每个要被删的数字左边和右边第一个比它小的没被删的数字的位置.然后从小到大枚举要被删的数, 求答案. #include<bits/stdc++.h> ...
- codeforces 140B.New Year Cards 解题报告
题目链接:http://codeforces.com/problemset/problem/140/B 题目意思:给出 Alexander 和他的 n 个朋友的 preference lists:数字 ...
- 【19.05%】【codeforces 731F】 Video Cards
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 1172E Nauuo and ODT [LCT]
Codeforces ZROI那题是这题删掉修改的弱化版--ZROI还我培训费/px 思路 按照套路,我们考虑每种颜色的贡献,然后发现不包含某种颜色的路径条数更容易数,就是删掉该颜色的点后每个连通块大 ...
- Codeforces 1172F Nauuo and Bug [线段树]
Codeforces 思路 定义\(f_{l,r}(x)\)表示数\(x\)从\(l\)进去\(r\)出来的时候会变成什么样子.容易发现这个函数是个分段函数,每一段都是斜率为1的一次函数,并且段数就是 ...
- Codeforces 1173B Nauuo and Chess
题目链接:http://codeforces.com/problemset/problem/1173/B 思路参考:https://www.cnblogs.com/blowhail/p/1099123 ...
随机推荐
- LINUXE下执行php 定时任务
linux test.php <?php $fn='/home/root.adminssh/boz/logs'; $data=rand(1,9999); $fp=fopen($fn,'wb'); ...
- java == 和equals()
== == 是运算符 :可以使用在基本数据类型变量和引用数据类型变量当中 : 如果比较的是基本数据类型变量,比较两个变量保存的数据是否相等(不一定类型相同) 如果比较的是引用数据类型变量, 比较两个对 ...
- 发送验证码倒计时60s
var wait=60; function time(o) { if (wait == 0) { o.removeClass("gray"); o.text("发送验证码 ...
- E. Covered Points (线段上的整点数)
题目链接:https://codeforces.com/contest/1036/problem/E 思路:学会了一个在线段上的整数点等于 GCD(x1 - x2, y1 - y2) + 1,然后去 ...
- angular-file-upload插件的使用简单介绍
参考博客: https://www.cnblogs.com/jarson-7426/p/5191156.html angular-file-upload 最近一段时间用了一下angular-file- ...
- 使用php的curl函数post返回值为301永久迁移的问题。(301 Moved Permanently)
本文链接:https://blog.csdn.net/Angus_01/article/details/82467652添加一行curl_setopt: curl_setopt($ch,CURLOPT ...
- Spring Cloud注册中心高可用搭建
Spring Cloud的注册中心可以由Eureka.Consul.Zookeeper.ETCD等来实现,这里推荐使用Spring Cloud Eureka来实现注册中心,它基于Netfilix的Eu ...
- 在mac版virtual box中安装ubuntu虚拟机的NAT/Host-Only网络配置踩坑记录
之前用惯了vmware和parallels desktop,网络配置十分智能,基本不用自己配置.由于版权原因,工作电脑上换了免费的virtual box用,四五年都完全在虚拟机里干活的本菜鸡居然在虚拟 ...
- linux/unix下setuid/seteuid/setreuid/setresuid
其中setresuid()具有最清晰的语法: setresuid()被执行的条件有: ①当前进程的euid是root ②三个参数,每一个等于原来某个id中的一个 如果满足以上条件的任意一个,setre ...
- 【java】读写文件
不要吐槽我为啥不写try,catch. 默认的相对路径是在工作空间的目录下. 如图 import java.io.*; import java.util.*; public class filerw ...