在C + npls中创建精简数组的最有效方法是什么?
答案: 3
对于C + npls,地图运行良好。 无数的东西不会成为麻烦。 在我的计算机系统上,1000万件事需要大约4.4秒,而且还需要57兆瓦。
我的考试申请是坚持:
#include <stdio.h>
#include <stdlib.h>
#include <map>
class triple {
public:
int x;
int y;
int z;
bool operator<(const triple &other) const {
if (x < other.x) return true;
if (other.x < x) return false;
if (y < other.y) return true;
if (other.y < y) return false;
return z < other.z;
}
};
int main(int, char**)
{
std::map<triple,int> data;
triple point;
int i;
for (i = 0; i < 10000000; ++i) {
point.x = rand();
point.y = rand();
point.z = rand();
//printf("%d %d %d %d\n", i, point.x, point.y, point.z);
data[point] = i;
}
return 0;
}
现在要动态选择各种变量,最方便的补救措施就是代表 index作为字符串 ,然后使用字符串作为地图的关键。 例如,位于[23] [55]的东西可以代表使用“23,55”字符串。 我们还可以扩展这种补救措施以进行更大的测量; 例如,对于3次测量,近似指数肯定类似于“34,45,56”。 这种策略的直接执行遵循:
std::map data<string,int> data;
char ix[100];
sprintf(ix, "%d,%d", x, y); // 2 vars
data[ix] = i;
sprintf(ix, "%d,%d,%d", x, y, z); // 3 vars
data[ix] = i;
0
Mark Harrison 2019-05-17 14:37:25
资源
分享
相关问题
0