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;
    }
    

      

  • 相关阅读:
    LeetCode(65) Valid Number
    LeetCode(57) Insert Interval
    Python 之scrapy框架58同城招聘爬取案例
    Python 之12306网站验证码校验案例
    Python 之selenium+phantomJS斗鱼抓取案例
    Python 之pytesseract模块读取知乎验证码案例
    Python 之糗事百科多线程爬虫案例
    Python 之beautifulSoup4解析库
    Python 之lxml解析库
    把一张的数据添加到另一张中
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10990891.html
Copyright © 2011-2022 走看看