强大的unique
强大的unique
两道红题为例眼熟一下unique
P1138 第k小整数
题解
这里用到了STL的去重函数哦
unique
首先你有一个待处理的数组 a[n]
一定要先排序鸭 sort( a+1 , a+n+1 )
然后 int nn=unique( a+1 , a+n+1 ) - (a+1)
这个nn就是去重后的数组长度,不重复而且排好序的数字就存在 a[1]~a[nn] 啦
重复的数字放在后面了 a[nn+1]~a[n]
注意这题有无解的情况QWQ
代码
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<queue> using namespace std; inline int read()
{
int ans=;
char last=' ',ch=getchar();
while(ch<''||ch>'') last=ch,ch=getchar();
while(ch>=''&&ch<='') ans=ans*+ch-'',ch=getchar();
if(last=='-') ans=-ans;
return ans;
} int n,k;
int a[]; int main()
{
n=read();k=read();
for(int i=;i<=n;i++) a[i]=read();
sort(a+,a+n+);
int kk=unique(a+,a+n+)-(a+);
if(k>kk) printf("NO RESULT\n");
else printf("%d\n",a[k]);
return ;
}
P1317 低洼地
题解
你考虑unique不先排序就去重
代码
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib> using namespace std; inline int read()
{
int ans=;
char last=' ',ch=getchar();
while(ch<''||ch>'') last=ch,ch=getchar();
while(ch>=''&&ch<='') ans=ans*+ch-'',ch=getchar();
if(last=='-') ans=-ans;
return ans;
} int n,ans=;
int a[]; int main()
{
n=read();
for(int i=;i<=n;i++)
a[i]=read();
int kk=unique(a+,a+n+)-(a+);
for(int i=;i<=kk;i++)
{
if(i==||i==kk) continue;
if(a[i-]>a[i]&&a[i]<a[i+])
ans++;
} printf("%d",ans);
return ;
}
强大的unique的更多相关文章
- jQuery数组($.each,$.grep,$.map,$.merge,$.inArray,$.unique,$.makeArray)处理函数详解
1. $.each(array, [callback]) 遍历[常用] 解释: 不同于例遍jQuery对象的$().each()方法,此方法可用于例遍任何对象.回调函数拥有两个参数:第一个为对象的成员 ...
- Laravel的unique和exists验证规则的优化
本文是Laravel实战:任务管理系统(一)的扩展阅读 原文链接:http://pilishen.com/posts/Improvements-to-the-Laravel-unique-and-ex ...
- 【原创】大叔案例分享(3)用户行为分析--见证scala的强大
一 场景分析 用户行为分析应用的场景很多,像线上网站访问统计,线下客流分析(比如图像人脸识别.wifi探针等),比较核心的指标有几个: PV | UV | SD | SC 指标说明: PV(Page ...
- 朱晔和你聊Spring系列S1E10:强大且复杂的Spring Security(含OAuth2三角色+三模式完整例子)
Spring Security功能多,组件抽象程度高,配置方式多样,导致了Spring Security强大且复杂的特性.Spring Security的学习成本几乎是Spring家族中最高的,Spr ...
- {MySQL完整性约束}一 介绍 二 not null与default 三 unique 四 primary key 五 auto_increment 六 foreign key 七 作业
MySQL完整性约束 阅读目录 一 介绍 二 not null与default 三 unique 四 primary key 五 auto_increment 六 foreign key 七 作业 一 ...
- iOS 强大第三方资源库
Github用法 git-recipesGit recipes in Chinese. 高质量的Git中文教程. lark怎样在Github上面贡献代码 my-git有关 git 的学习资料 giti ...
- 将VIM打造成强大的IDE
转载自:所需即所获:像 IDE 一样使用 vim 如侵犯您的版权,请联系:2378264731@qq.com --------------------------------------------- ...
- 强大的JQuery数组封装使用
JQuery对数组的处理非常便捷并且功能强大齐全,一步到位的封装了很多原生js数组不能企及的功能.下面来看看JQuery数组的强大之处在哪. $.each(array, [callback]) 遍历 ...
- .Net强大的列表控件XPTable [转]
.Net强大的列表控件XPTable http://blog.csdn.net/bodybo/article/details/7359531 XPTable的大名,想必C#开发的人都有所耳闻,使用下来 ...
随机推荐
- mysql复制表的方法
## 跨库复制表的方法 使用navicat 直接使用navicat的 转储sql文件 结构+数据 mysqldump 备份导出 导入 (数据库备份-恢复) mysqldump -h链接ip -P(大写 ...
- jquery 取指定class下的input checkbox选中的值
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- collections:内建模块,提供额外的集合类
介绍 collections里面包含了很多除了内置类型之外的数据类型,我们使用它们有时可以很方便的完成一系列操作 ChainMap:搜索多个字典 from collections import Cha ...
- redis编译和安装出现错误
redis编译到时候出现错误,记录一下原因 1.下载redis,https://redis.io/download ,一般选择稳定版本,稳定版的版本号是偶数,当前最新版本是5.0.4,Linux可直接 ...
- 使用 Eclipse 构建的时候会出现 run as 中没有 maven package 选项
注:该方法来自我学习时别人分享的出现问题的解决方法,并没有亲自测试,仅供参考 是因为建的是普通 java 工程,需要把它转换成 maven project. 1.右键工程--maven--Disabl ...
- 数据库——Oracle(5)
1 唯一约束: 1)修改表的时候设置唯一约束 alter table 表名 add constraint 约束名 unique(列名1,列名2,列名3...) create table worker8 ...
- IntelliJ IDEA 如何设置代码提示和代码模板
在编写java代码时如何设置不分大小写提示和设置快捷输出模板代码 首先设置不分大小写,settings-Editor-General-CodeCompletion 将红框的Match case取消打勾 ...
- Python中关于txt的简单读写模式与操作
Python中关于txt的简单读写操作 常用的集中读写模式: 1.r 打开只读文件,该文件必须存在. 2.r+ 打开可读写的文件,该文件必须存在. 3.w 打开只写文件,若文件存在则文件长度清为0,即 ...
- pycharm 快捷键及一些常用设置
pycharm中的快捷键及一些常用设置 在PyCharm /opt/pycharm-3.4.1/help目录下可以找到ReferenceCard.pdf快捷键英文版说明 PyCharm Default ...
- 2019.8.30 记录一个Swiper的使用
导入 flutter_swiper: ^1.1.6 引入 import 'package:flutter_screenutil/flutter_screenutil.dart'; 已下 ...