opencv中礼帽和黑帽

Problem statement:

问题陈述:

There is a class of N students and the task is to find the top K marks-scorers. Write a program that will print the index of the toppers of the class which will be same as the index of the student in the input array (use 0-based indexing). First print the index of the students having highest marks then the students with second highest and so on. If there are more than one students having same marks then print their indices in ascending order.

有一班N名学生,任务是找到得分最高的K分。 编写一个程序,该程序将打印班级排行榜的索引,该索引将与输入数组中学生的索引相同(使用基于0的索引)。 首先打印得分最高的学生的索引,然后打印第二高的学生的索引,依此类推。 如果有多个具有相同分数的学生,则以升序打印索引。

Input Example:

输入示例:

Suppose k = 2 and the students having highest marks have indices 0 and 5 and students having second highest marks have indices 6 and 7 then output will be 0 5 6 7.

假设k = 2,并且分数最高的学生的索引为0和5,分数第二高的学生的索引为6和7,那么输出将为0 5 6 7。

    K=2
N=10
Marks are:
97 84 82 89 84 97 95 95 84 86
Output:
0 5 6 7, so there are four toppers for K=2

97 & 95 is to be considered. There are four students who has got this. Their indices are 0 5 6 7 (For a particular marks if there is more than one student, their indices needs to printed in ascending order).

97和95将被考虑。 有四个学生已经得到了这个。 他们的索引是0 5 6 7(对于一个特定的标志,如果有一个以上的学生,他们的索引需要以升序打印)。

Solution:

解:

Data structure used:

使用的数据结构:

  1. Set (ordered in decreasing fashion)

    集合(以降序排列)

  2. Map (ordered in decreasing fashion)

    地图(以降序排列)

Algorithm:

算法:

  1. Need to store the marks in sorted way descending order.

    需要以降序存储标记。

  2. The marks are key and we need to map student indices to the key value. While mapping indices needed to be mapped in ascending fashion.

    分数是关键,我们需要将学生索引映射到关键值。 而映射索引需要以升序方式进行映射。

  3. Print indices for K keys ( marks value already sorted in decreasing fashion, thus top K keys are top K marks).

    K个键的打印索引(标记值已经按降序排序,因此,前K个键是前K个标记)。

Implementation with the data structures used:

用所使用的数据结构实现:

  1. Declare records as a map.

    将记录声明为地图。

    map&ltint, vector<int>, greater <int>> records;
    
    map<> = ordered map usually ordered in ascending fashion as per key value greater <int> is used to order in descending fashion.

    Here our key is integer type which maps to a vector of integer. Clearly the key is marks & which maps to a list of indices of students.

    在这里,我们的键是整数类型,它映射到整数向量。 显然,关键是标记&,它映射到学生的索引列表。

  2. Declare numbers as a set.

    将数字声明为一组。

    set<int, greater<int>> numbers;
    
    set<> = ordered set usually ordered in ascending fashion as per element value greater <int> is used to order in descending fashion.

    Here the elements are the marks which are stored in sorted descending fashion.

    这里的元素是标记,它们以降序存储。

  3. After completion of the input taking, both records&numbers are filled with datas as per mentioned previously.

    输入完成后,两个记录和编号都填充了前面提到的数据。

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

Let's consider the above input example:

让我们考虑上面的输入示例:

    K=2
N=10
Marks are:
97 84 82 89 84 97 95 95 84 86

So after completion of input taking:

因此,在完成输入之后:

Records looks like:

记录如下:

Numbers looks like:

数字看起来像:

K=2, thus we need to print indices only for marks 97, 95

K = 2,因此我们只需要为标记97、95打印索引

Thus the indices to be print are: 0 5 6 7

因此要打印的索引为: 0 5 6 7

So to print:

所以要打印:

For i =0: K
Set iterator tonumbers.begin() //points to 97
Advance iterator by i; //to point at ith mark from the top
Print the vector list associated with the key (marks) pointed to.
END FOR
.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

类的Toppers的C ++实现 (C++ implementation for Toppers of Class)

#include <bits/stdc++.h>
using namespace std;
int main()
{int n,k;
//n is no of students, k is the input K
cout<<"enter no of student\n";
scanf("%d",&n);
map<int,vector<int>,greater <int>> records;//declare records
set<int,greater<int>> numbers;//declare numbers
int no;
cout<<"enter the marks of the students\n";
for(int i=0;i<n;i++){cin>>no;
//for key value build the vector list
records[no].push_back(i);
//to avoid duplicate
if(numbers.find(no)==numbers.end())
numbers.insert(no); //insert marks to set
}
cout<<"enter K\n";
cin>>k; //input K
cout<<"Toppers are: ";
//printing the indices
for(int i=0;i<k;i++){
auto ij=numbers.begin();
advance(ij,i);
//printing the associated vector
for(auto it=records[*ij].begin();it!=records[*ij].end();it++){
printf("%d ",*it);
}
}
cout<<endl;
return 0;
}

Output

输出量

enter no of student
10
enter the marks of the students
97 84 82 89 84 97 95 95 84 86
enter K
2
Toppers are: 0 5 6 7

翻译自: https://www.includehelp.com/icp/toppers-of-class.aspx

opencv中礼帽和黑帽

opencv中礼帽和黑帽_一流的礼帽相关推荐

  1. 基于python的opencv图像形态学处理(图像腐蚀与膨胀操作以及礼帽与黑帽)

    腐蚀与膨胀 图像的腐蚀与膨胀互为逆向操作,通常用于处理二值图像(黑白图,以黑色为底面背景),因此需要先进行二值化处理,腐蚀和膨胀通俗的理解就是,在指定大小的卷积核内,如果该卷积核内全为黑色或全为白色, ...

  2. python+OpenCv笔记(七):图像的形态学操作(腐蚀与膨胀、开闭运算、礼帽与黑帽)

    一.腐蚀与膨胀 腐蚀就是原图中高亮的部分被蚕食,效果图拥有比原图更小的高亮区域. 腐蚀的作用是:消除物体边界点,使目标缩小,可以消除小于结构元素的噪声点. 膨胀就是使原图中高亮的部分扩张,效果图拥有比 ...

  3. OpenCV 礼帽和黑帽

    礼帽运算 原图像与"开运算"的结果图之差,如下式计算: 因为开运算带来的结果是放大了裂缝或者局部低亮度的区域,因此,从原图中减去开运算后的图,得到的效果图突出了比原图轮廓周围的区域 ...

  4. 【opencv学习】【形态学】【腐蚀与膨胀】【开运算与闭运算】【礼帽和黑帽】

    一:膨胀和腐蚀 原始图像如下: hw.png hw_inv.png 如下展示代码: import numpy as np import random import cv2 import matplot ...

  5. OpenCV梯度运算、礼帽与黑帽

    # 梯度=膨胀-腐蚀 pie_t = cv2.imread("pie.png") kernel_t = np.ones((5,5),np.uint8) digete_t = cv2 ...

  6. OpenCV 礼帽与黑帽

    形态学-腐蚀操作 img = cv2.imread('sleep.png')kernel = np.ones((5, 5), np.uint8) erosion = cv2.erode(img, ke ...

  7. OpenCV_05 形态学操作:连通性+腐蚀和膨胀+开闭运算+礼帽和黑帽

    1 连通性 在图像中,最小的单位是像素,每个像素周围有8个邻接像素,常见的邻接关系有3种:4邻接.8邻接和D邻接.分别如下图所示: 4邻接:像素p(x,y)的4邻域是:(x+1,y):(x-1,y): ...

  8. Seo劫持---网站SEO优化中常见的黑帽技术:蜘蛛劫持

    很多seo人员喜欢黑帽技术,毕竟那是快速提升排名的方法.但是小编在这里告诫大家:如果你不是专业的黑客,还是放弃这种想法吧,因为那不是一般人能玩的.那么今天小编就来分享一些常见解决办法.下面我们来谈谈网 ...

  9. 网站中木马病毒黑帽非法信息处理

    网站中木马病毒黑帽非法信息处理 3.17突然收到邮件说我服务器有webshell,发现是有2个网站的缓存文件夹runtime里有后门,但是这个文件夹不能关闭写入权限一旦关闭网站都无法打开.于是只是清理 ...

最新文章

  1. ASP.NET编程中的十大技巧【转载】
  2. 根据输入时间段备份压缩日志文件
  3. java derby连接_JAVA-Derby连接
  4. linux 安装sysstat使用iostat、mpstat、sar、sa
  5. 二叉查找树(BST Binary Search Tree)
  6. ue4材质节点怎么用_济南装修:阳台储物柜用什么材质好?怎么保养阳台储物柜?...
  7. tomcat增加处理线程数量
  8. python主函数入口_python类 + mian()函数
  9. 亲个嘴竟然有这么大的学问
  10. 如何用Python画QQ表情中的滑稽脸
  11. 太阳系(Python)
  12. My second page-数组删除 —— By Nicolas
  13. Elastic基本概念
  14. 设置Shell脚本开机自启
  15. 微软语音引擎 TTS 最基本使用
  16. MSP430F149串口收发程序详解
  17. Update join 修正数据
  18. 点餐推荐系统_麦当劳智慧餐厅的微信小程序终究将取代人工点餐和自助点餐机...
  19. jupyter python2_【精】Jupyter Notebook同时支持Python2和Python环境
  20. [转]Cortex-a8 arm11 arm9 xscale powerpc 嵌入式处理器实测性能

热门文章

  1. 监控在服务器中的作用和功能,视频安防监控服务器能实现哪些功能以及解决哪些问题呢...
  2. 计算机考研复试-数据库
  3. 在word 2013中输入latex公式
  4. 画质提升了! LR增强细节_Lightroom 开启 AI 照片细节强化:画面清晰度提升 30%
  5. 2008游戏服务器系统下,Linux系统下玩经典游戏 CS1.5服务器架设
  6. 小米路由器青春版装linux,小米路由器青春版没有USB接口,如何连接小米WiFi放大器...
  7. stm32f407小车控制板:电机函数
  8. 商务工作汇报年终总结PPT模板
  9. luajit开发文档wiki中文版(二) LuaJIT 扩展
  10. 2021年全国规模以上工业企业运行现状分析:实现利润总额87092.1亿元 两年平均增长18.2% [图]