强大的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#开发的人都有所耳闻,使用下来 ...
随机推荐
- 分布式消息中间件之kafka设计思想及基本介绍(一)
Kafka初探 场景->需求->解决方案->应用->原理 我该如何去设计消息中间件--借鉴/完善 场景 跨进程通信(进程间生产消费模型) 需求 基本需求 实现消息的发送和接收. ...
- 8.8.ZooKeeper 原理和选举机制
1.ZooKeeper原理 Zookeeper虽然在配置文件中并没有指定master和slave但是,zookeeper工作时,是有一个节点为leader,其他则为follower,Leader是通 ...
- STM32/MINI
- DBSCAN算法及sklearn实现
基本概念:(Density-Based Spatial Clustering of Application with Noiso) 1.核心对象: 若某个点的密度达到算法设定的阈值则其为核心点.(即r ...
- 异步消息处理机制相关面试问题-AsyncTask面试问题详解
什么是AsyncTask: 它本质上是一个封装了线程池和handler的异步框架. AsyncTask的使用方法: 三个参数: 五个方法: AsyncTask的内部原理: AsyncTask的注意事项 ...
- java8学习之Stream介绍与操作方式详解
关于默认方法[default method]的思考: 在上一次[http://www.cnblogs.com/webor2006/p/8259057.html]中对接口的默认方法进行了学习,那在Jav ...
- 关于GRPC的讲解
gRPC服务发现&负载均衡 https://segmentfault.com/a/1190000008672912?utm_source=tag-newest GRPC编程指南 gRPC 介绍 ...
- 1024·程序员节来啦!MyEclipse致敬改变世界的程序猿
1024·程序员狂欢季 MyEclipse/CodeMix — Java开发利器!现金红包免费领! 快拆开看你的最大优惠券是多少,幸运奖红包翻倍! (活动期间在线下单的客户才可享受此优惠,过期恢复 ...
- hadoop fs –stat 命令
当向HDFS上写文件时,可以通过设置dfs.blocksize配置项来设置文件的block size,这导致HDFS上不同文件的block size是不同的.有时候我们需要知道HDFS上某个文件的bl ...
- 【代码备份】ORACLE数据库表同步DBLINK
---创建目标数据库连接DBLINKcreate database link testdblink connect to xxx identified by "xxx"using ...