zoukankan      html  css  js  c++  java
  • Codeforces Round #418 A

    A. An abandoned sentiment from past

    题意:给一个长度为n的数组a和一个长度为k的数组b,问将数组a中的0用b数组的元素来替换(b数组中一个数只能替换一次),如果存在一种可能替换使得a成为非递增数列,输出Yes,否则输出No

    思路:如果a数组中0的个数大于1,那么一定是Yes,因为0的个数大于1的情况下,如果可以构成一个递增数列,那么将其中2个替换的数调换一下,则构成了非递增数列,所以0大于2一定可以构成非递增数列,只有当0的个数为1(或者0),且替换后是递增数列的情况才是No

    AC代码:

    #include "iostream"
    #include "string.h"
    #include "stack"
    #include "queue"
    #include "string"
    #include "vector"
    #include "set"
    #include "map"
    #include "algorithm"
    #include "stdio.h"
    #include "math.h"
    #define ll long long
    #define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
    #define mem(a) memset(a,0,sizeof(a))
    using namespace std;
    const int N=1e5+100;
    int n,k,f,ff,m,a[200],b[200];
    int main(){
        cin>>n>>k;
        f=0,ff;
        a[0]=-1000,a[n+1]=1000;
        for(int i=1; i<=n; ++i){
            cin>>a[i];
            if(a[i]==0){
                f++;
                m=i;
            }
            else if(a[i]<=a[i-1]){
                ff=1;
            }
        }
        for(int i=1; i<=k; ++i){
            cin>>b[i];
        }
        if(ff==0 && f==1){
            for(int i=1; i<=k; ++i){
                if(b[i]>a[m-1] && b[i]<a[m+1]){
                    cout<<"No";
                    return 0;
                }
            }
        }
        cout<<"Yes";
        return 0;
    }
    /*
    4 2
    11 0 0 14
    5 4
    6 1
    2 3 0 8 9 10
    5
    4 1
    8 94 0 4
    89
    7 7
    0 0 0 0 0 0 0
    1 2 3 4 5 6 7
    */
  • 相关阅读:
    HashMap源码分析
    LinkedList源码分析
    ArrayList源码学习
    Java容器知识总结
    Collections 工具类和 Arrays 工具类常见方法
    Java基础知识
    MySQL高级之索引优化分析
    MySQL命令大全
    Java IO
    SpringCloud笔记
  • 原文地址:https://www.cnblogs.com/max88888888/p/7096415.html
Copyright © 2011-2022 走看看