为什么好多次做题都这样,样例对了还不给过?
#include<iostream>
#include<cstdio>
using namespace std;
int MX[9],ML[16],MR[16],S[9][9],ans=0;
void print()
{
ans++;
cout<<"NO. "<<ans<<endl;
for(int i=1;i<=8;i++)
{
for(int j=1;j<=8;j++)
{
cout<<S[j][i]<<" ";
}
cout<<endl;
}
}
void DFS(int y)
{
if(y==9)
{
print();
}
else
{
int Y=y+1;
for(int i=1;i<=8;i++)
{
if(MR[Y+i-1]==0 && ML[Y-i+8]==0 && MX[i]==0)
{
S[y][i]=1;
MR[Y+i-1]=1;
ML[Y-i+8]=1;
MX[i]=1;
DFS(Y);
MR[Y+i-1]=0;
ML[Y-i+8]=0;
MX[i]=0;
S[y][i]=0;
}
}
}
}
int main()
{
DFS(1);
}
@ada;
回答一下
上代码:
#include <string>
#include <iostream>
using namespace std;
class A
{
public:
int m_i;
A(int a) :m_i(a)
{
cout << "A:A(int a)构造函数执行" << " ,id: " << this_thread::get_id() << endl;
}
A(const A &a) :m_i(a.m_i)
{
cout << "A:A(const A &a)构造函数执行" << " ,id: " << this_thread::get_id() << endl;
}
~A()
{
cout << "析构函数执行" << " ,id: " << this_thread::get_id() << endl;
}
void thread_work(int n)
{
cout << "thread_work执行了" << n << " ,id: " << this_thread::get_id() << endl;
}
};
int main()
{
int mvar = 1;
int mysecondpar = 12;
A a(10);
thread mytobj(&A::thread_work, a,10);
mytobj.join();
//mytobj.detach();
cout << "主线程结束" << endl;
//system("pause");
return 0;
}
主要注意用法的不同:
依次为成员函数、类对象、需要传入函数的参数。
thread mytobj(&A::thread_work, a,10);
运行结果:
可以尝试,这里的类对象仍可以用ref来引用并操作。
需要注意的是,子线程使用的对象会调用该类的拷贝构造函数。
多线程的内容需要不断积累和总结,内容虽然繁杂,但并不困难,多加练习和与实际应用相结合,便能加深理解。