zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    算法---十大经典排序算法
    算法---待整理
    iOS面试题整理---[难度]***
    spring mvc(注解)上传文件的简单例子
    面试感悟:3年工作经验程序员应有的技能
    一个 IT 青年北漂四年的感悟
    成为更优秀程序员的关键:更多的阅读
    数组参数 有params 区别
    对C# 集合类的总结
    c#前缀
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10990891.html
Copyright © 2011-2022 走看看