http://www.geeksforgeeks.org/given-an-array-of-of-size-n-finds-all-the-elements-that-appear-more-than-nk-times/

这一题如果没空间要求就没那么麻烦了

 #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <fstream>
#include <map>
using namespace std; void more(int arr[], int n, int k) {
map<int, int> S;
for (int i = ; i < n; i++) {
if (S.find(arr[i]) != S.end()) S[arr[i]]++;
else if (S.size() == k) {
for (map<int, int>::iterator it = S.begin(); it != S.end(); it++) {
if (it->second == ) S.erase(it->first);
else it->second--;
}
}
else S[arr[i]] = ;
}
for (map<int, int>::iterator it = S.begin(); it != S.end(); it++) {
int tmp = ;
for (int i = ; i < n; i++) {
if (arr[i] == it->first) tmp++;
}
if (tmp > n / k) cout << it->first << " ";
}
} int main() {
int arr[] = {, , , , , , };
more(arr, , );
return ;
}

Data Structure Array: Given an array of of size n and a number k, find all elements that appear more than n/k times的更多相关文章

  1. LeetCode Two Sum III - Data structure design

    原题链接在这里:https://leetcode.com/problems/two-sum-iii-data-structure-design/ 题目: Design and implement a ...

  2. [Swift]LeetCode211. 添加与搜索单词 - 数据结构设计 | Add and Search Word - Data structure design

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  3. [Algorithm] Trie data structure

    For example we have an array of words: [car, done, try, cat, trie, do] What is the best data structu ...

  4. 面试总结之数据结构(Data Structure)

    常用数据结构及复杂度 http://www.cnblogs.com/gaochundong/p/3813252.html 常用数据结构的时间复杂度 Data Structure Add Find De ...

  5. [Algorithm] Heap data structure and heap sort algorithm

    Source, git Heap is a data structure that can fundamentally change the performance of fairly common ...

  6. [LeetCode] 170. Two Sum III - Data structure design 两数之和之三 - 数据结构设计

    Design and implement a TwoSum class. It should support the following operations:add and find. add - ...

  7. sklearn中报错ValueError: Expected 2D array, got 1D array instead:

    from sklearn.linear_model import LinearRegression lr = LinearRegression() print(tr_x.shape,tr_y.shap ...

  8. 决策树python建模中的坑 :ValueError: Expected 2D array, got 1D array instead:

    决策树python建模中的坑 代码 #coding=utf-8 from sklearn.feature_extraction import DictVectorizerimport csvfrom ...

  9. [已解决]报错:ValueError: Expected 2D array, got scalar array instead

    报错代码: new_x = 84610 pre_y = model.predict(new_x) print(pre_y) 报错结果: ValueError: Expected 2D array, g ...

随机推荐

  1. 未能从程序集“Oracle.ManagedDataAccess”加载 “OracleInternal.Common.ConfigBaseClass”

    使用VS2015做项目的过程中一直使用的服务器上的oracle数据库,后来想学习一下oracle,就在本机安装了oracle.可没想到本来运行好好的项目,现在不能运行了.项目是使用的Abp框架,当运行 ...

  2. jenkins插件安装失败更改插件源

    看提示的日志说是下载失败,应该是网络问题 最好的办法就是更改下载源 [系统管理][管理插件][高级]升级站点项的的地址修改成 修改之后,安装了一下git的插件速度非常快,jenkins镜像地址列表ht ...

  3. delphi的基本数据类型

    2017年06月07日 11:02:25 阅读数:402 分类 范围 字节 备注 简单类型 序数 整数 Integer -2147483648 .. 2147483647 4 有符号32位 Cardi ...

  4. 从两张Excel表所想到的

    从两张Excel表所想到的 前几日,客服妹子发过来几张表,让我给她做下匹配,然后做了,想了,便有了这篇博文,不由感慨,看似简简单单的两张Excel表其实藏着好多东西,记叙如下,与君共勉. 最初的需求: ...

  5. MS coco数据集下载

    2017年12月02日 23:12:11 阅读数:10411 登录ms-co-co数据集官网,一直不能进入,FQ之后开看到下载链接.有了下载链接下载还是很快的,在我这儿晚上下载,速度能达到7M/s,所 ...

  6. 使用Firebug进行断点调试详解

    利用Firebug我们可以非常方便地对网页上的任何JavaScript代码进行断点调试. 首先,使用快捷键F12在当前页面打开Firebug,并切换到脚本选项卡. 其次,我们需要为指定的js代码添加断 ...

  7. hdu 1598 find the most comfortable road(并查集)

    题意:略 分析:多询问问题,利用并查集加速.类似于kruskal对MST的构建:枚举最小的边,逐渐将更大的边加入集合,当查询的点在同一个集合,那么当前最小值,就是所加的最后一条边与第一条只差. 注意: ...

  8. Debian Epson L455 打印机

    要使用打印机必须要在本机(或局域网其他机器)上安装打印服务,L455是网络打印机,需要IPP协议,而mDNS-scan和avahi-utils是用来发现网络打印机的服务,由于我是摸索着安装的,没太研究 ...

  9. win10 下eclipse tomcat 热部署问题?

    前言: 问题的描述: 用的环境是maven,java,tomcat,win10 tomcat server配置如下 项目发布之后,修改jsp,报错,错误详情如下: 解决办法.勾选server opti ...

  10. 【WPF学习笔记】之WPF基础:依赖关系属性和通知

    这些天来,对象似乎已经忙得晕头转向了.每个人都希望它们做这做那.Windows® Presentation Foundation (WPF) 应用程序中的典型对象会接到各种各样不同的请求:有要求绑定到 ...