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 ...
随机推荐
- Python | 安装和配置智能提示插件Anaconda (转)
作为Python开发环境的Sublime Text 3,有了Anaconda就会如虎添翼.Anaconda是目前最流行也是最有威力的Python代码提示插件. 工具/原料 Sublime Text ...
- 基于C#的波形显示控件的实现[转]
编者记: 09年暑假正好在学院实验室呆了一段时间,做了个完整的上位机软件(具体实现:根据下位机的指令,实现通过串口来操纵下位机进行实验,并将采集的数据进行处理和保存,并以图形的方式显示),整个项目边学 ...
- Python编写购物小程序
购物车要求: 用户名和密码存放于文件中 启动程序后,先登录,登录成功则让用户输入工资,然后打印商品列表,失败则重新登录,超过三次则退出程序 允许用户根据商品编号购买商品 用户选择商品后,检测余额是否够 ...
- 分布式ID生成器的解决方案总结
在互联网的业务系统中,涉及到各种各样的ID,如在支付系统中就会有支付ID.退款ID等.那一般生成ID都有哪些解决方案呢?特别是在复杂的分布式系统业务场景中,我们应该采用哪种适合自己的解决方案是十分重要 ...
- mongo聚合命令
db.getCollection('chat').aggregate([ { "$match": { "last": 1, "type": ...
- 【目录】ASP.NET Core 2.1 入门教程
ASP.NET Core 2.1 快速学习.入门系列教程,这个入门系列教程为了帮助大家快速上手ASP.NET Core. 本教程包含且不限于: 使用VS Code开发ASP.NET Core应用 AS ...
- spring纯注解的account案例
dao层: package cn.mepu.dao.imp; import cn.mepu.dao.IAccountDao; import cn.mepu.domain.Account; import ...
- Vs 中的智能提示,默认选中,切换快捷键
切换是否默认选中,快捷键: Ctrl+Alt+Space(空格)
- html浮动小问题
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- IntelliJ IDEA 添加本地xsd文件
地址: http://code.alibabatech.com/schema/dubbo/dubbo.xsd