Codeforces Round #418 A--An abandoned sentiment from past
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 kequals 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 b should 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.
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 andb respectively.
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 "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
4 2
11 0 0 14
5 4
Yes
6 1
2 3 0 8 9 10
5
No
4 1
8 94 0 4
89
Yes
7 7
0 0 0 0 0 0 0
1 2 3 4 5 6 7
Yes
题意就是把b数组插到a数组的0中
只有有一个不是递增序列,那就输出Yes
所以我们把b按照递减序列排序
只要b递减后 a还是递增 那这个序列就递增 反之递减
1 #include <cctype> 2 #include <cstdio> 3 #include <algorithm> 4 5 using namespace std; 6 7 const int MAXN=1010; 8 9 int n,m; 10 11 int a[MAXN],b[MAXN],q[MAXN]; 12 13 inline void read(int&x) { 14 int f=1;register char c=getchar(); 15 for(x=0;!isdigit(c);c=='-'&&(f=-1),c=getchar()); 16 for(;isdigit(c);x=x*10+c-48,c=getchar()); 17 x=x*f; 18 } 19 20 inline bool cmp(int a,int b) { 21 return a>b; 22 } 23 24 int hh() { 25 int t=0; 26 read(n);read(m); 27 for(int i=1;i<=n;++i) read(a[i]); 28 for(int i=1;i<=m;++i) read(b[i]); 29 sort(b+1,b+1+m,cmp); 30 for(int i=1;i<=n;++i) if(!a[i]) a[i]=b[++t]; 31 for(int i=1;i<n;++i) 32 if(a[i]>a[i+1]) { 33 printf("Yes\n"); 34 return 0; 35 } 36 printf("No\n"); 37 return 0; 38 } 39 40 int sb=hh(); 41 int main(int argc,char**argv) {}
---恢复内容结束---
作者:乌鸦坐飞机
出处:http://www.cnblogs.com/whistle13326/
新的风暴已经出现
怎么能够停止不前
穿越时空 竭尽全力
我会来到你身边
微笑面对危险
梦想成真不会遥远
鼓起勇气 坚定向前
奇迹一定会出现