zoukankan      html  css  js  c++  java
  • Codeforces Round #418 (Div. 2) A

    Description

    A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.

    To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.

    Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in bshould be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total.

    If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.

    Input

    The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and brespectively.

    The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai≤ 200) — Hitagi's broken sequence with exactly k zero elements.

    The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence.

    Input guarantees that apart from 0, no integer occurs in a and b more than once in total.

    Output

    Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.

    Examples
    input
    4 2
    11 0 0 14
    5 4
    output
    Yes
    input
    6 1
    2 3 0 8 9 10
    5
    output
    No
    input
    4 1
    8 94 0 4
    89
    output
    Yes
    input
    7 7
    0 0 0 0 0 0 0
    1 2 3 4 5 6 7
    output
    Yes
    Note

    In the first sample:

    • Sequence a is 11, 0, 0, 14.
    • Two of the elements are lost, and the candidates in b are 5 and 4.
    • There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".

    In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.

    题意:给出一组数字,缺少的数字用0表示,下一行给出可以填充的数字,问你填充之后能不能形成非递增的数列

    解法:把第二组数字从大到小排序,依次插入然后判断就好

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define ll long long
     4 const int maxn=123456;
     5 int a,b,c;
     6 int x[maxn],y[maxn];
     7 int flag;
     8 int ze=0;
     9 vector<int>q;
    10 bool cmd(int x,int y)
    11 {
    12     return x>y;
    13 }
    14 int main()
    15 {
    16     cin>>a>>b;
    17     for(int i=1;i<=a;i++)
    18     {
    19         cin>>x[i];
    20 
    21     }
    22     for(int i=1;i<=b;i++)
    23     {
    24         cin>>y[i];
    25     }
    26     int cnt=1;
    27     sort(y+1,y+1+b,cmd);
    28     for(int i=1;i<=a;i++)
    29     {
    30         if(x[i])
    31         {
    32             q.push_back(x[i]);
    33         }
    34         else
    35         {
    36             q.push_back(y[cnt++]);
    37         }
    38     }
    39     int ans=q[0];
    40     for(int i=1;i<q.size();i++)
    41     {
    42         if(ans>=q[i])
    43         {
    44             cout<<"Yes"<<endl;
    45             return 0;
    46         }
    47         else
    48         {
    49             ans=q[i];
    50         }
    51     }
    52     cout<<"No"<<endl;
    53     return 0;
    54 }
  • 相关阅读:
    Visual Studio日志
    选择jQuery的理由
    第三方开发者可将JIT和编译器引入WinRT吗?
    Visual Studio 2012和.NET 4.5已经就绪!
    500TB——Facebook每天收集的数据量
    Netflix开源他们的另一个架构——Eureka
    PhoneGap 2.0 发布
    快速哈希算法破坏了加密的安全性
    Blend for Visual Studio 2012:为Windows 8应用所用的UX工具
    系统中的故障场景建模
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/6961173.html
Copyright © 2011-2022 走看看