CF

xiaoxiao2021-02-28  143

Codeforces Round #418 (Div. 2) A.An abandoned sentiment from past

题目传送门

题目描述:

  给定两个序列a,b。将a序列中值为0的数填入b序列的数。如果可以组成非递增序列,则输出Yes,否则输出No

解题思路:

  试想如果a数组里面值为0的数大于1,则肯定组不成递增序列。因为你可以让那两个数成为递减的序列。所以这道题就可以分两种情况来讨论,第一种,a数组中的为0的个数等于1;第二种大于1。
  当大于1的时候直接输出Yes
  当等于1的时候,把那个b填进去,判断a序列是否为递增数列即可。

注意:

  必须是严格递增,如果相等不算递增序列
代码部分
#include <iostream> #include <stdio.h> #include <string.h> #include <set> #include <map> #include <algorithm> #include <string> using namespace std; int main() { int a[105],b[105]; int n,k; while(~scanf("%d%d",&n,&k)) { int temp; for(int i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]==0) temp=i; } for(int i=0;i<k;i++) scanf("%d",&b[i]); if(k>1) { printf("Yes\n"); continue; } else { a[temp]=b[0]; int ans=-1; bool flag=true; for(int i=0;i<n;i++) { if(a[i]<=ans) flag=false; ans=a[i]; } if(flag) printf("No\n"); else printf("Yes\n"); } } return 0; }
转载请注明原文地址: https://www.6miu.com/read-69533.html

最新回复(0)