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. Eclipse 常用快捷键清单

    罗列了一些常用的快捷键(显红为很实用的快捷键) Ctrl+Shift+L:快速打开所有快捷键列表 一.文件 F2 :快速打开信息提示.重命名F3 :打开声明(同Ctrl+左鼠)F4 :打开类型层次结构 ...

  2. appium----基本概念

    转:http://www.cnblogs.com/nbkhic/p/3803830.html Client/Server Architecture appium的核心其实是一个暴露了一系列REST A ...

  3. linux系统下面ftp的一些命令

    service vsftpd restart重启vsftpd服务service vsftpd stop停止vsftpd服务service vsftpd start启动vsftpd服务 chkconfi ...

  4. android开发游记:meterial design 5.0 开源控件整套合集 及使用demo

    android 的5.0公布不光google官方给出了一些新控件,同一时候还给出了一套符合material design风格的设计标准,这套标准将未来将覆盖google全部产品包括pc端,站点,移动端 ...

  5. 不同手机根据坐标计算控件、图片的像素,px 与 dp, sp换算公式?

    参考该帖子:http://www.cnblogs.com/bluestorm/p/3640786.html PPI = Pixels per inch,每英寸上的像素数,即 "像素密度&qu ...

  6. 大数据hadoop之zookeeper

    一.ZooKeeper 的实现 1.1 ZooKeeper处理单点故障 我们知道可以通过ZooKeeper对分布式系统进行Master选举,来解决分布式系统的单点故障,如图所示. 图 1.1 ZooK ...

  7. Mockito when(...).thenReturn(...)和doReturn(...).when(...)的区别

    在Mockito中打桩(即stub)有两种方法when(...).thenReturn(...)和doReturn(...).when(...).这两个方法在大部分情况下都是可以相互替换的,但是在使用 ...

  8. 对Mybatis的理解

    首先Mybatis是一个对象关系映射(Object Relational Mapping,简称ORM)框架,是为了解决面向对象与关系数据库存在的互不匹配的现象.也就是说Mybatis的关注点在于对象与 ...

  9. poj1066(叉乘的简单应用)

    做完了才发现,好像没有人和我的做法一样的,不过我怎么都觉得我的做法还是挺容易想的. 我的做法是: 把周围的方框按顺时针编号,然后对于每一条边,如果点出现在边的一侧,则把另一侧所有的点加1,这样最后统计 ...

  10. 【BZOJ2119】股市的预测 后缀数组+分块

    [BZOJ2119]股市的预测 Description 墨墨的妈妈热爱炒股,她要求墨墨为她编写一个软件,预测某只股票未来的走势.股票折线图是研究股票的必备工具,它通过一张时间与股票的价位的函数图像清晰 ...