Codeforce 814A - 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 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 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 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 "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
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.
题解:实际上如果m>1的或就直接输出yes,不要想太多,因为已经保证每个数字只出现一遍,而如果m>1的话,b中的数就必定有大小关系,所以直接输出yes。
这样一来m就只能为1了,把b放进a判断一下是否递增就可以了。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
const int N=;
const int mod=1e9+;
int a[],b[];
int n,m,cnt;
int main()
{
int i,j;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]==)cnt=i;
}
for(i=;i<=m;i++)
scanf("%d",&b[i]);
if(m>){
cout<<"Yes";
return ;
}
i=cnt;
a[i]=b[];
for(i=;i<=n;i++){
if(a[i]<a[i-]){
cout<<"Yes";
return ;
}
}
cout<<"No";
return ;
}
Codeforce 814A - An abandoned sentiment from past (贪心)的更多相关文章
- An abandoned sentiment from past
An abandoned sentiment from past time limit per test 1 second memory limit per test 256 megabytes in ...
- Codeforces Round #418 (Div. 2) A+B+C!
终判才知道自己失了智.本场据说是chinese专场,可是请允许我吐槽一下题意! A. An abandoned sentiment from past shabi贪心手残for循环边界写错了竟然还过了 ...
- codeforces round 418 div2 补题 CF 814 A-E
A An abandoned sentiment from past 水题 #include<bits/stdc++.h> using namespace std; int a[300], ...
- 冬训 day2
模拟枚举... A - New Year and Buggy Bot(http://codeforces.com/problemset/problem/908/B) 暴力枚举即可,但是直接手动暴力会非 ...
- Codeforce 835B - The number on the board (贪心)
Some natural number was written on the board. Its sum of digits was not less than k. But you were di ...
- codeforce Gym 100685E Epic Fail of a Genie(MaximumProduction 贪心)
题意:给出一堆元素,求一个子集,使子集的乘积最大,如有多个,应该使子集元素个数尽量小. 题解:贪心,如果有大于1的正数,那么是一定要选的,注意负数也可能凑出大于1的正数,那么将绝对值大于1的负数两两配 ...
- codeforce 810B Summer sell-off (贪心 排序)
题意: 商店准备用n天售货(每天的货物都是一样的),第i天会卖ki件货物,并且会有li个顾客来买. 如果货物没卖完, 那么每个顾客一定会买一件. 如果货物有剩, 不会保存到第二天. 现在给定一个f, ...
- Codeforce 1255 Round #601 (Div. 2) A. Changing Volume (贪心)
Bob watches TV every day. He always sets the volume of his TV to bb. However, today he is angry to f ...
- Codeforce 140C (贪心+优先队列)补题
C. New Year Snowmen time limit per test2 seconds memory limit per test256 megabytes inputstandard in ...
随机推荐
- WEB测试用例设计总结
1易用性 1.便于使用.理解.并能减少用户发生错误选择的可能性 2.当数据字段过多时,使用便于用户迅速吸取信息的方式表现信息,突出重点信息,标红等方式 3.显示与当前操作相关的信息,给出操作提示. 4 ...
- 使用 HTMLTestRunner 模块生成HTML格式的测试报告文件
1.下载HTMLTestRunner.py HTMLTestRunner 是 Python 标准库的 unittest 模块的一个扩展.它生成易于使用的 HTML 测试报告.HTMLTestRunne ...
- 爬虫mm131明星照片
''' 1. 爬取以下站点中各个明星图片,分别单独建文件夹存放. 起始URL地址:http://www.mm131.com/mingxing ''' import os import logging ...
- 用PE系统安装原版XP
方法:直接运行Winnt32程序进行XP原版系统安装. [1].在PE系统中将XP SP3系统镜像ISO文件从U盘上复制到硬盘的非系统分区后,用PE所带WinRAR程序将该ISO镜像中的I386 ...
- NYOJ 圈水池
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i ...
- Stylus的使用
vue-cli项目安装使用stylus步骤:1. npm install stylus -D命令,在项目内安装stylus.(注意:命令结尾 -D 即是 --save-dev 的简写形式) 2.需要安 ...
- map的使用方式之一。
map有返回值 foreach 没得.. 得到结果 可以把里面的值以数组的方式取出来: 举例:
- layui透明弹框
效果: layui.use('layer', function () { var layer = layui.layer; var str = '<div>'; str += '<d ...
- ecshop 前台分页
在当前需要分页的if最后div里面加入这句, <!-- #BeginLibraryItem "/library/pages.lbi" --><!-- #EndLi ...
- MyBatis基础入门《十八》动态SQL(if-where)
MyBatis基础入门<十八>动态SQL(if-where) 描述: 代码是在<MyBatis基础入门<十七>动态SQL>基础上进行改造的,不再贴所有代码,仅贴改动 ...