在c ++中.我将bitset初始化为-3,如:
std::bitset<32> mybit(-3);
Run Code Online (Sandbox Code Playgroud)
是否存在转换mybit为的优雅方式-3.因为bitset对象只有像to_ulong和的方法to_string.
给出两个正整数a,b(1 <= a <= 30,1 <= b <= 10000000),并定义两个不可重复的集合L和R,
L = {x * y | 1 <= x <= a, 1 <= y <= b, x,y is integer}
R = {x ^ y | 1 <= x <= a, 1 <= y <= b, x,y is integer},
Run Code Online (Sandbox Code Playgroud)
^是异或操作
对于任何两个整数:A∈L,B∈R,我们将B格式化为n + 1(n是b的十进制数字)十进制数字(在B前面填0),然后将B连接到A的末尾并获得一个新的整数AB.
计算所有生成的整数AB的总和(如果总和超过,只返回"sum mod 1000000007",mod表示模块化运算)
注意:算法的时间不超过3秒
我的算法非常简单:我们可以很容易地得到集合R中的最大数,并且R中的元素是0,1,2,3 ... maxXor,(元素max(a,b)可能不在R中) ,使用哈希表计算集L. 但是当a = 30,b = 100000时算法消耗4秒.
举个例子:
a = 2, b = 4, so
L = {1 * 1, 1 …Run Code Online (Sandbox Code Playgroud) 我想在c ++ 11中使用正则表达式,gcc 4.8.2支持它.但MinGW安装程序仅支持gcc 4.8.1.如何将其更新为gcc 4.8.2?
class Singleton
{
private:
static Singleton s;
Singleton(){}
public:
static Singleton *getInstance()
{
return &s;
}
};
Singleton Singleton::s;
Run Code Online (Sandbox Code Playgroud)
这是一个有效的单身人士课程吗?
class Singleton
{
private:
static Singleton *m_instance;
Singleton(){}
public:
static Singleton *getInstance()
{
return m_instance;
}
};
Singleton * Singleton::m_instance = new Singleton;
Run Code Online (Sandbox Code Playgroud)
.
class Singleton
{
private:
static Singleton *m_instance;
Singleton(){}
public:
static Singleton *getInstance()
{
if(m_instance == NULL)
{
lock();
if(m_instance == NULL)
m_instance = new Singleton;
unlock();
}
return m_instance;
}
};
Singleton * Singleton::m_instance = NULL; …Run Code Online (Sandbox Code Playgroud)