code forces 1173 C. Nauuo and Cards
本文链接:https://www.cnblogs.com/blowhail/p/10990833.html
Nauuo and Cards
原题链接:http://codeforces.com/contest/1173/problem/C
题目大意 :有2n张卡片,其中n张编号为1-n,另外n张为0. 现在手中拿n张,桌子上放n张,每次操作可以在桌子上底部放入一张卡片,最上面拿走一张卡片,问最小操作次数。
思路: 先看看卡片1的位置,卡片1在桌子上时,看看是否满足从1递增到底部,例如 0 0 1 2 3 4 。如果满足就依次插入卡片,取出卡片。
如果1在手中,就开始依次插入卡片,取出卡片,从1开始,插入1之后,如果2卡片此时仍然在桌子上的卡组里,操作次数+1,取出最前面的卡片,继续判断2卡片。(这里意思是如果2不在手里,就要等2拿到之后再插入,相当于在1卡片的前面插入了0卡片,即1卡片插入的次数延后)
代码如下:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int a[],b[],c[];
int main ()
{
int i,t,m,n,u,sum=,maxs,mins,x,y=,z;
scanf("%d",&n);
for(i=;i<=n;++i){
scanf("%d",&t);
a[t]++;
c[t]++; //a,c数组记录手中的卡牌
}
for(i=;i<=n;++i)
scanf("%d",&b[i]);
int j,k;
if(a[]==) //判断1在不在手中
{
for(i=;i<=n;++i)
if(b[i]==)
{
k=;j=;
while(j) // 1在桌子上的卡组时,判断1后面是否依次递增到最后一张
{
if(i==n)
{
break;
}
else
{
i++;
k++;
if(b[i]!=k)
{
j=;
}
}
}
if(!j)
break;
}
}
k=;
if(j) //如果从卡片1到最后一张都是依次递增的,判断能否继续往后添加卡片
{
x=b[n]+;
if(x-==n) //如果正好桌上的牌满足1-n递增放好
k=;
for(i=;i<=n;++i){
if(c[x]==)
sum++;
else {
break;
}
c[ b[i] ]++; //取出最前面的卡片 if(x>=n) //顺利放完全部卡片
k=;
x++;
}
}
if(k){
printf("%d\n",sum);
return ;
}
//如果卡片1在手中
sum=;
int p=;
for(i=; ;++i)
{
if(a[p]==) //将卡片p放入,如果此时卡片p不存在,操作数+1 ,取出最前面的卡片 (相当于在卡片1前面插入一张0卡片)
p++; a[ b[i] ]++; //取出最前面的卡片
sum++; //记录操作次数
if(p==n+)
break;
}
printf("%d\n",sum); return ;
}
code forces 1173 C. Nauuo and Cards的更多相关文章
- code forces 1173 B. Nauuo and Chess
本文链接:https://www.cnblogs.com/blowhail/p/10991237.html B. Nauuo and Chess 原题链接:http://codeforces.com ...
- 思维题--code forces round# 551 div.2
思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...
- Code Forces 796C Bank Hacking(贪心)
Code Forces 796C Bank Hacking 题目大意 给一棵树,有\(n\)个点,\(n-1\)条边,现在让你决策出一个点作为起点,去掉这个点,然后这个点连接的所有点权值+=1,然后再 ...
- Code Forces 833 A The Meaningless Game(思维,数学)
Code Forces 833 A The Meaningless Game 题目大意 有两个人玩游戏,每轮给出一个自然数k,赢得人乘k^2,输得人乘k,给出最后两个人的分数,问两个人能否达到这个分数 ...
- 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 ...
- code force 401B. Game of Credit Cards
B. Game of Credit Cards time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Code Forces 543A Writing Code
题目描述 Programmers working on a large project have just received a task to write exactly mm lines of c ...
- code forces 383 Arpa's loud Owf and Mehrdad's evil plan(有向图最小环)
Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...
- code forces 382 D Taxes(数论--哥德巴赫猜想)
Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...
随机推荐
- Beginner’s Tutorial: 3D Line and Border Effects in XAML
This mini-tutorial might be for you if you’re having troubles finding the right line colors to achie ...
- XenServer重置存储管理SR至Ext3
Xenserver默认安装到本地磁盘,它是基于本地磁盘上Linux的LVM所管理,在xenserver创建为LVM Typer的本地SR,xenserver在LVM上不支持Thin Provision ...
- Apache 配置 HTTPS访问
将需要配置的项目移动到另一根目录下,作为https访问位置. 修改bitnami配置文件..\Bitnami\wampstack-5.6.19-0\apache2\conf\bitnami\bitna ...
- WPF编游戏系列 之八 银行界面及金额校验
原文:WPF编游戏系列 之八 银行界面及金额校验 在前面<WPF编游戏系列 之四 用户控件>一文中通过用户控件创建了"My Shop"中物品列表框.本篇继 ...
- WPF DataGrid自动生成列
<Window x:Class="DataGridExam.MainWindow" xmlns="http://schemas.microsoft.c ...
- C# dotnetcore2.0结合Selenium搜索网页
using System; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; namespace ConsoleApp_Selenium { c ...
- System.Data.SQLite 中GUID的处理
原文:System.Data.SQLite 中GUID的处理 项目中正好用到System.Data.SQLite,在手持上使用这个数据库,因为要做数据同步,所以表中的主键都是Guid的数据类型. 在数 ...
- 如何计算memcache的容量
在容量足够的情况下,当然是越大越好,但这样会造成浪费.不考虑这种情况.我们一般的情况是: memcache集群一开始创建会根据存储的数据量与访问量进行容量大小的估算.再算一个20%的冗余. 在网站快速 ...
- Android零基础入门第48节:可折叠列表ExpandableListView
原文:Android零基础入门第48节:可折叠列表ExpandableListView 上一期学习了AutoCompleteTextView和MultiAutoCompleteTextView,你已经 ...
- Cannot read property 'apply' of undefined
...TypeError: Cannot read property 'apply' of undefined :一般都是作用域不对 ...TypeError: Cannot read propert ...