Codeforces Round #479 (Div. 3) C. Less or Equal

题目地址:http://codeforces.com/contest/977/problem/C
题解:给一串数组,是否找到一个数x,找到k个数字<=x,找到输出x,不能输出-1。例如第二组,要找到两个数字,排序后出现1,3,3,会出现三个数字小于等于3,所以不能找到。
一个坑点,k=0的时候需要分类讨论,如果发现最小的数字是1的话,不能输出0,因为要求输出1~1e9之间的数,否则输出a[0]-1就可以啦~
方法:排序以后分类判断即可。
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
int a[];
int main()
{
int n, k;
cin >> n >> k;
for (int i = ; i < n; i++)
{
cin >> a[i];
}
sort(a, a + n);
if (k == )
{
if (a[] == )
printf("-1\n");
else
printf("%d\n", a[] - );
}
else if (k == n)
{
printf("%d\n", a[n - ]);
}
else
{
if (a[k - ] == a[k])
{
printf("-1\n");
}
else
{
printf("%d\n", a[k - ]);
}
}
return ;
}
Codeforces Round #479 (Div. 3) C. Less or Equal的更多相关文章
- Codeforces Round #479 (Div. 3) C. Less or Equal (排序,贪心)
题意:有一个长度为\(n\)的序列,要求在\([1,10^9]\)中找一个\(x\),使得序列中恰好\(k\)个数满足\(\le x\).如果找不到\(x\),输出\(-1\). 题解:先对这个序列排 ...
- Codeforces Round #479 (Div. 3) A. Wrong Subtraction
题目网址:http://codeforces.com/contest/977/problem/A 题解:给你一个数n,进行k次变换,从末尾开始-1,512变成511,511变成510,510会把0消掉 ...
- Codeforces Round #479 (Div. 3) F. Consecutive Subsequence (简单dp)
题目:https://codeforces.com/problemset/problem/977/F 题意:一个序列,求最长单调递增子序列,但是有一个要求是中间差值都是1 思路:dp,O(n)复杂度, ...
- Codeforces Round #479 (Div. 3)解题报告
题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...
- Codeforces Round #479 (Div. 3) B. Two-gram
原题代码:http://codeforces.com/contest/977/problem/B 题解:有n个字符组成的字符串,输出出现次数两个字符组合.例如第二组样例ZZ出现了两次. 方法:比较无脑 ...
- Codeforces Round #479 (Div. 3) 题解 977A 977B 977C 977D 977E 977F
A. Wrong Subtraction 题目大意: 定义一种运算,让你去模拟 题解: 模拟 #include <iostream> #include <cstdio> ...
- Codeforces Round #479 (Div. 3)题解
CF首次推出div3给我这种辣鸡做,当然得写份博客纪念下 A. Wrong Subtraction time limit per test 1 second memory limit per test ...
- Codeforces Round #479 (Div. 3)
手速场2333,这群人贼牛逼!手速贼快! A. Wrong Subtraction time limit per test 1 second memory limit per test 256 m ...
- E. Cyclic Components (DFS)(Codeforces Round #479 (Div. 3))
#include <bits/stdc++.h> using namespace std; *1e5+; vector<int>p[maxn]; vector<int&g ...
随机推荐
- MyBatis主键生成器Jdbc3KeyGenerator(二)
上一篇博客MyBatis主键生成器KeyGenerator(一)中我们大体介绍了主键生成器的接口及配置等,接下来我们介绍一下KeyGenerator的实现类Jdbc3KeyGenerator Jdbc ...
- Unity UGUI基础之Toggle
Toggle组合按钮(单选框),可以将多个Toggle按钮加入一个组,则他们之间只能有一个处于选中状态(Toggle组合不允许关闭的话). 一.Toggle组件: Toggle大部分属性等同于Butt ...
- x264 编码器选项分析 (x264 Codec Strong and Weak Points) 2
文章目录: x264 编码器选项分析 (x264 Codec Strong and Weak Points) 1 x264 编码器选项分析 (x264 Codec Strong and Weak Po ...
- 《java入门第一季》之根据小案例体会泛型
泛型在哪些地方使用呢? * 看API,如果类,接口,抽象类后面跟的有<E>就说要使用泛型.一般来说就是在集合中使用. 下面根据案例,加深体会泛型的作用. 案例一: import java. ...
- oracle ORA-00917: missing comma 是因为少逗号
oracle ORA-00917: missing comma 是因为少逗号,而且不是网上盛传的空格问题!都是传言误人啊
- 学习TensorFlow,邂逅MNIST数据集
如果说"Hello Word!"是程序员的第一个程序,那么MNIST数据集,毫无疑问是机器学习者第一个训练的数据集,本文将使用Google公布的TensorFLow来学习训练MNI ...
- 【FPGA学习】Verilog之加法器
在fpga工程应用设计中,随处可见加法器,乘法器等等.现在将一些常用模块和心得体会先记录下来,以便日后使用. 一位半加器: module halfadder(cout,sum,a,b); output ...
- Leetcode_104_Maximum Depth of Binary Tree
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41964475 Maximum Depth of Binar ...
- Cocos2d中update与fixedUpdate的区别(六)
它如何工作呢? update:和fixedUpdate:方法实际这样工作. Cocos2D将从iOS接口中取得时间间隔(delta)在你的游戏代码执行期间,并且检查fixedUpdate:方法在间隔期 ...
- AngularJS进阶(十五)Cookie 'data' possibly not set or overflowed because it was too large
Cookie 'data' possibly not set or overflowed because it was too large (5287 > 4096 bytes)! 注:请点击此 ...