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 day she was playing cards but found that the cards were mixed with some empty ones.

There are nn cards numbered from 11 to nn, and they were mixed with another nn empty cards. She piled up the 2n2n cards and drew nn of them. The nn cards in Nauuo's hands are given. The remaining nn cards in the pile are also given in the order from top to bottom.

In one operation she can choose a card in her hands and play it — put it at the bottom of the pile, then draw the top card from the pile.

Nauuo wants to make the nn numbered cards piled up in increasing order (the ii-th card in the pile from top to bottom is the card ii) as quickly as possible. Can you tell her the minimum number of operations?

思路:

先考虑能不能直接出完。

再考虑出几个0之后,一起把n张牌出完。

假设第i张牌再第二个数组中的位置是pi,可以得到只有当其处在i-1这个位置时。才能一下n步出完。

得到res = max(res, pi-i+1+n).

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;

map<int, int> In;
int a[MAXN];

int main()
{
//    freopen("test.in", "r", stdin);
    cin >> n;
    for (int i = 1;i <= n;i++)
        cin >> a[i], In[a[i]] = 0;
    for (int i = 1;i <= n;i++)
        cin >> a[i], In[a[i]] = i;
    if (In[1])
    {
        int i = 2;
        for (;In[i] == In[i-1]+1;i++);
        if(In[i-1] == n)
        {
            int j;
            for (j = i;j <= n && In[j] <= j-i;j++);
            if (j > n)
            {
                cout << n-i+1 << endl;
                return 0;
            }
        }
    }
    int res = 0;
    for (int i = 1;i <= n;i++)
        res = max(res, In[i]-i+1+n);
    cout << res << endl;

    return 0;
}

  

转载于:https://www.cnblogs.com/YDDDD/p/10990891.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值