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. cisco 为每个单独的人员设置不同的用户名和密码

    cisco 为每个单独的人员设置不同的用户名和密码 2010-12-15 17:00:16 分类: 系统运维 Router1#configure terminalEnter configuration ...

  2. git统计代码行数

    查看个人指定时期内代码行数,注意将 --author="user.name" 替换成自己的用户名 git log --since="2018-07-16" -- ...

  3. CNN 防止过拟合的方法

    CNN 防止过拟合的方法 因为数据量的限制以及训练参数的增多,几乎所有大型卷积神经网络都面临着过拟合的问题,目前常用的防止过拟合的方法有下面几种:      1. data augmentation: ...

  4. php优化(php.ini)

    PHP优化 ------------------------------------- 尽量选择php5.4及以上的版本,里面很多优化参数已经移除了相比以前版本   1.引擎解析优化和加速 1)eac ...

  5. 关于并发模型 Actor 和 CSP

    最近在看<七天七并发模型>这本书,在书上介绍了 Actor 和 CSP 这两种并发模型.这两种模型很像,但还是有一些不同的地方.看完之后,比较困扰的是: 在什么场合使用哪种模型比较好呢? ...

  6. org.hibernate.type.SerializationException: could not deserialize 反序列化失败

    1.查看实体类有没有实现Serializable接口 例:public class Student implements Serializable { ***** } 2.看表中的字段有没有在实体中进 ...

  7. JavaWeb学习总结第六篇--认识Session机制

    认识Session机制 前文也提到过,常用的会话跟踪有两种技术:Cookie和Session.今天就为大家讲解一下Session机制. 什么是Session? Session是另一种记录客户状态的机制 ...

  8. EasyAR SDK在unity中的简单配置及构建一个简单场景。

    首先打开EasyAR的官方网站http://www.easyar.cn/index.html,注册登陆之后,打开首页的开发页面. 下载sdk和Unity Samples. 创建一个unity3d工程N ...

  9. Zxing二维码解析——图文转换

    一:文字转化为二维码图片. package com.xhm.tool; import java.util.Hashtable; import android.graphics.Bitmap; impo ...

  10. 微信小程序之云开发一

    最近听说微信小程序发布了云开发,可以不需要购买服务器,就能开发小程序和发布小程序,对于动辄千元的服务器,极大的节约了开发成本,受不住诱惑,我就开始了小程序的云开发,目前项目已上线,亲测不收费,闲不住的 ...