本文整理汇总了C++中Mat::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::clear方法的具体用法?C++ Mat::clear怎么用?C++ Mat::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat
的用法示例。
在下文中一共展示了Mat::clear方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
int ncases;
cin >> ncases;
cin.ignore();
int nnum, mnum;
char cstate;
Statement *s;
vector<Statement> slist;
for(int i=0; i<ncases; i++) {
cin >> nnum;
cin >> mnum;
for(int j=0; j<mnum; j++) {
s = new Statement();
cin >> s->teller;
cin >> cstate;
if( cstate=='T' ) {
s->state = T_STATE;
} else if( cstate=='L' ) {
s->state = L_STATE;
} else if( cstate=='S' ) {
s->state = S_STATE;
} else if( cstate=='D' ) {
s->state = D_STATE;
}
cin >> s->lhs;
if( s->state==S_STATE || s->state==D_STATE ) cin >> s->rhs;
slist.push_back(*s);
}
sort(slist.begin(), slist.end(), cmp_teller_asc);
Mat *lmat = new Mat(mnum, nnum, 0); // statement matrix..
Mat *rmat = new Mat(nnum, 1, 0); // matrix for modular equation(answer)..
Mat *umat = new Mat(mnum, 1, 0); // result matrix..
convert_matrix_form(slist, lmat, umat);
solve_matrix_modular(lmat, rmat, umat, 2);
cout << "Case #" << i+1 << ": " << rmat->p[0][0];
for(int j=1; j<nnum; j++) cout << " " << rmat->p[j][0];
cout << endl;
lmat->clear();
rmat->clear();
umat->clear();
slist.clear();
}
return 0;
}
示例2: deleteFeature
// This function if to delete the feature with index in indexList.
void deleteFeature(Mat &dataSet, Row &featureName, vector<int> &indexList) {
if (dataSet.size() == 0)
return;
Mat matTemp = dataSet;
Row featureNameTemp = featureName;
dataSet.clear();
featureName.clear();
int dataRowSize = (int)matTemp[0].size();
vector<int> indexIsDelete(dataRowSize);
for (int i = 0; i != dataRowSize; ++i)
indexIsDelete[i] = 0;
for (auto item : indexList)
indexIsDelete[item] = 1;
for (auto row : matTemp) {
Row rowTemp;
for (int i = 0; i < dataRowSize; ++i) {
if(indexIsDelete[i] == 0) {
rowTemp.push_back(row[i]);
}
}
dataSet.push_back(rowTemp);
}
for (int i = 0; i < featureNameTemp.size(); ++i) {
if (indexIsDelete[i] == 0)
featureName.push_back(featureNameTemp[i]);
}
}
示例3: main
int main()
{
//freopen("out", "w", stdout);
freopen("in", "r", stdin);
cin >> n >> k;
for(int i = 0; i < n; ++i) cin >> num[i];
Mat mt;
mt.clear();
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
long long tmp = num[i] ^ num[j];
int cnt = 0;
for(int k = 0; k < 63; ++k) {
if(tmp & (1LL << k)) {
cnt++;
}
}
if(cnt % 3 == 0) {
mt.mat[i][j] = 1;
}
}
}
mt = mt ^ (k - 1);
long long ans = 0;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
ans += mt.mat[i][j];
}
}
cout << ans % MOD << endl;
return 0;
}
示例4:
Mat operator * (Mat a, Mat b) {
Mat r;
r.clear();
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
for (int k = 0; k < 2; ++k)
add(r.d[i][k], (1LL * a.d[i][j] * b.d[j][k]) % mod);
return r;
}
示例5:
Mat operator * (Mat a,Mat b)
{
Mat c;
c.clear();
for ( int i = 0 ; i < n ; i++)
for ( int j = 0 ; j < n ; j++)
for (int k = 0 ; k < n ; k++)
c.mat[i][j] =(c.mat[i][j]+a.mat[i][k]*b.mat[k][j])%MOD;
return c;
}
示例6: calc
Mat calc(int ql, int qr, int l, int r, int rt) {
if (ql <= l && r <= qr) {
return tr[rt];
}
int mid = (l + r) >> 1;
if (!mt[rt].chk()) {
tr[rt<<1] = tr[rt<<1] * mt[rt];
tr[rt<<1|1] = tr[rt<<1|1] * mt[rt];
mt[rt<<1] = mt[rt<<1] * mt[rt];
mt[rt<<1|1] = mt[rt<<1|1] * mt[rt];
mt[rt].init();
}
Mat ret;
ret.clear();
if (ql <= mid)
ret = ret + calc(ql, qr, l, mid, rt<<1);
if (mid < qr)
ret = ret + calc(ql, qr, mid+1, r, rt<<1|1);
return ret;
}
示例7: SecondClassArchive
void SortIntoStorage::SecondClassArchive(Mat &first)
{
Mat second; //临时存储系统
vector<int> temp;
vector <int>::iterator Iter;
bool flag = true; //标志跳出所有循环
for (int i = 1; i < 6; i++)
{
for (unsigned int j = 0; j < first[i].size(); j++)
{
for (unsigned int k = 0; k < first[0].size(); k++)
{
if (first[0][k] == first[i][j]) //从所有文件中剔除文件直至为空
{
temp.push_back(first[0][k]);
for (Iter = first[0].begin(); Iter != first[0].end(); Iter++)
{
if (*Iter == first[0][k]) //删除特定位置的元素
{
Iter = first[0].erase(Iter);
}
if (Iter == first[0].end()) //控制迭代器不能超过整个容器
break;
}
break;
}
}
if (first[0].size() == 0)
{
flag = false;
break;
}
}
second.push_back(temp); //有可能为空
temp.clear();
if (flag == false)
break;
}
first.clear();
for (unsigned int m = 0; m < second.size(); m++)
{
if (second[m].size() != 0)
{
first.push_back(second[m]);
}
second[m].clear();
}
for (unsigned int p = 0; p < first.size(); p++)
{
cout <<p+1<<"号归档文件" << endl;
for (unsigned int q = 0; q < first[p].size(); q++)
{
cout << first[p][q] << endl;
}
}
unsigned int sizeOfFirst = first.size();
first.clear();
//删繁就简,将first[m]简化成int,将int赋值在rand()阈值之外,确保它与一般文件(随机数)的区别
//降维,多维全都简化成一维
for (unsigned int p = 0; p < sizeOfFirst; p++)
{
temp.push_back(++thresholdValue);
first.push_back(temp);
temp.clear(); //记得中间变量在使用过后清理存储,否则会导致数据重复存储
}
}
示例8: FirstClassArchive
//用随机数模拟不断加入的各种不同的文件,暂时不考虑文件相同的情况,即随机数有可能重复
//申请动态数组
void SortIntoStorage::FirstClassArchive(unsigned int n, Mat& first)
{
int *ary = NULL;
vector<int> temp,totalFiles,A, B, C, D, E; //假设共有5个分布式存储容器
for (unsigned int p = 0; p < first.size(); p++)
{
for (unsigned int q = 0; q < first[p].size(); q++) //传进来的first[p].size()一定是1
{
temp.push_back(first[p][q]); //中间变量用于ary[i]
}
}
ary = new int[n + first.size()];
if (ary == NULL)
cout << "分配给数组的存储空间失败!" << endl;
srand(unsigned(time(NULL))); //用系统当前时间的无符号整数值初始化随机数生成器的启动值
for (unsigned int i = 0; i < (n+first.size()); i++)
{
vector<int> choices;
if (i < first.size())
ary[i] = temp[i];
else ary[i] = rand(); //返回0~32767的随机值
for (int j = 0; j < 3; j++) //生成两个副本,随机存放在存储容器里
{
choices.push_back(rand() % 5+1); //在1~5内产生3个不同的随机数,选存储容器
for (int k = 0; k < j; k++)
{
if (choices[j] == choices[k]) //如果与之前产生的随机数相同就重新生成再比较
{
choices.pop_back(); //删除最后一个元素
choices.push_back(rand() % 5+1);
k = -1;
}
}
for (int p = 0; p < 1; p++) //配合break,跳出循环仍停在j循环里
{
switch (choices[j])
{
case 1:A.push_back(ary[i]);
break;
case 2:B.push_back(ary[i]);
break;
case 3:C.push_back(ary[i]);
break;
case 4:D.push_back(ary[i]);
break;
case 5:E.push_back(ary[i]);
break;
default:cout << "存放异常!" << endl;
}
}
}
totalFiles.push_back(ary[i]);
}
first.clear();
first.push_back(totalFiles); //存放所有文件,包括从first进来的已归档文件
first.push_back(A);
first.push_back(B);
first.push_back(C);
first.push_back(D);
first.push_back(E);
totalFiles.clear();
A.clear();
B.clear();
C.clear();
D.clear();
E.clear();
delete[]ary;
ary = NULL;
}