当前位置:网站首页>std::set compare
std::set compare
2022-06-12 16:21:00 【seventeen billion five hundred and six million three hundred an】
#include <iostream>
#include <string>
#include <set>
#include <cmath>
#include <vector>
class SubSetIndexComparator
{
private:
int m_length;
public:
SubSetIndexComparator(int arrayLength) : m_length(arrayLength) {}
bool operator()(const int* arr1, const int* arr2) const
{
std::cout << "AAAA" << std::endl;
// All sizes should be compared , Otherwise, there will be ambiguity
// Sort from small to large
for (int i = 0; i < m_length; i++)
{
std::cout << "i=" << i << " " << arr1[i] << " " << arr2[i] << std::endl;
if (arr1[i] < arr2[i])
{
return true;
}
if (arr1[i] > arr2[i])
{
return false;
}
}
return false;
}
};
int main()
{
int iterations = 0;
int maxIterations = 10;
double k = maxIterations;
int minimalFitNum = 3;
int numSamples = 4;
std::vector<int> shuffled_indices(numSamples);// For taking initial samples
int* cur_init_sub_set_indexs = NULL; // Initially selected samples
// The point set index flag of the current model ,currentVotes[i] Conform to current model settings 1, otherwise 0
short* currentVotes = new short[numSamples];
SubSetIndexComparator subsetIdxComparator(minimalFitNum);
std::set<int*, SubSetIndexComparator > chosen_sub_sets(subsetIdxComparator);
while (iterations < k)
{
// Randomly select... From the dataset n A little bit
cur_init_sub_set_indexs = new int[minimalFitNum];
// Reset
for (int i = 0; i < (int)shuffled_indices.size(); i++)
{
shuffled_indices[i] = i;
}
for (int i = 0; i < minimalFitNum; i++)
{
std::swap(shuffled_indices[i], shuffled_indices[i + rand() % (numSamples - i)]);
}
memset(currentVotes, 0, numSamples * sizeof(short));
for (int i = 0; i < minimalFitNum; i++)
{
cur_init_sub_set_indexs[i] = shuffled_indices[i];
currentVotes[shuffled_indices[i]] = 1;
}
#if 0
for (int i = 0; i < (int)shuffled_indices.size(); i++)
{
std::cout << shuffled_indices[i] << " " << currentVotes[i] << std::endl;
}
#endif
std::cout << std::endl;
for (int i = 0; i < minimalFitNum; i++)
{
std::cout << cur_init_sub_set_indexs[i] << std::endl;
}
// See if you have used this subset
std::pair< std::set<int*, SubSetIndexComparator >::iterator, bool > res = chosen_sub_sets.insert(cur_init_sub_set_indexs);
if (res.second)//true, Indicates successful insertion , This subset is used for the first time
{
std::cout << "TRUE" << std::endl;
}
std::cout << "=========" << std::endl;
iterations++;
}
std::cout << "" << std::endl;
// Traversal data , Iterate through the data with an iterator
for (std::set<int*, SubSetIndexComparator>::iterator it = chosen_sub_sets.begin(); it != chosen_sub_sets.end(); ++it)
{
for (int i = 0; i < minimalFitNum; i++)
{
std::cout << (*it)[i] << " ";
}
std::cout << std::endl;
}
/*
// custom comparison
std::set<Point, PointCmp> z = { {1, 0}, {1, 1}, {3, 4}, {2, 5} };
z.insert({ 2, -1 }); // this fails because the magnitude of 1,-1 equals 1,1
for (auto& p : z) std::cout << '(' << p.x << ',' << p.y << ") ";
std::cout << '\n';
*/
return 0;
}边栏推荐
- In 2021, China's lottery sales generally maintained a rapid growth, and the monthly sales generally tended to be stable [figure]
- The C Programming Language(第 2 版) 笔记 / 8 UNIX 系统接口 / 8.2 低级 I/O(read 和 write)
- Acwing 1927 automatic completion (knowledge points: hash, bisection, sorting)
- <山东大学项目实训>渲染引擎系统(三)
- Interview: what are shallow copy and deep copy?
- Acwing794 high precision Division
- PostgreSQL source code (53) plpgsql syntax parsing key processes and function analysis
- Global and Chinese markets of automatic glue applicators 2022-2028: Research Report on technology, participants, trends, market size and share
- 批量--03---CmdUtil
- The C Programming Language(第 2 版) 笔记 / 8 UNIX 系统接口 / 8.4 随机访问(lseek)
猜你喜欢

Super detailed dry goods! Docker+pxc+haproxy build a MySQL Cluster with high availability and strong consistency

Review of the development of China's medical beauty (medical beauty) industry in 2021: the supervision is becoming stricter, the market scale is expanding steadily, and the development prospect is bro

Applet: how to get the user's mobile number in the plug-in

Project training of Software College of Shandong University rendering engine system radiation pre calculation (IX)

Sum of acwing796 submatrix

Cookie 和 Session

Project training of Software College of Shandong University rendering engine system radiation pre calculation (VIII)

Acwing794 high precision Division

批量--04---移动构件

RTOS rt-thread裸机系统与多线程系统
随机推荐
面试:hashCode()和equals()
小程序:如何在插件中获取用户手机号
Office VR porn, coquettish operation! The father of Microsoft hololens resigns!
Thread pool execution process
Servlet API
Sum of acwing796 submatrix
Development practice of ag1280q48 in domestic CPLD
leetcode-54. Spiral matrix JS
Project training of Software College of Shandong University rendering engine system basic renderer (6)
acwing 801. Number of 1 in binary (bit operation)
Project training of Software College of Shandong University rendering engine system radiation pre calculation (IX)
The small flying page is upgraded to be intelligent and the bug repair is faster
面试:为什么整数包装类尽量用equals()来比较大小
MYSQL---服务器配置相关问题
面试:什么是浅拷贝、深拷贝?
Multimix:从医学图像中进行的少量监督,可解释的多任务学习
Interview: do you understand the packing and unpacking operations?
acwing 798二维差分(差分矩阵)
连续八年包装饮用水市占率第一,这个品牌DTC是如何持续增长的?
5-5配置Mysql复制 基于日志点的复制