常变量在定义变量时,如果加上关键字const,则变量的值在程序运行期间不能改变,这种变量称为常变量(constant variable)。例如,const int a=3; //用const来声明这种变量的值不能改变,指定其值始终为3在定义常变量时必须同时对它初始化(即指定其值),...
分类:
其他好文 时间:
2014-07-15 08:58:55
阅读次数:
203
联通块是指给定n个点,输入a,b(1#includeusing namespace std;const int maxn=1010;int p[maxn];//作为每个独立的点 int sum[maxn];//每个节点下面连接的点 int find(int x) {if(x==p[x])return...
分类:
移动开发 时间:
2014-07-14 22:21:30
阅读次数:
403
模板原型:解决零散数点在已知线段上的出现次数。思想是将线段用长线覆盖,将长线转化成线段树。用权值记录各个数点出现的次数,最后进行查询。代码解释见注释。 1 #include 2 using namespace std; 3 4 const int MAXN = 3e4 + 10; 5 int n.....
分类:
其他好文 时间:
2014-07-14 21:47:46
阅读次数:
173
部分函数已验证是正确的,还没有完全验证所有的函数有没有写正确 1 #include 2 using namespace std; 3 4 const double eps = 1e-10; 5 int dcmp(double x){//等于0 0;大于0 1;小于0 -1 6 ...
分类:
其他好文 时间:
2014-07-14 14:30:15
阅读次数:
180
经验:当我们编写一个 class template, 而它所提供之"与此 template 相关的"函数支持"所有参数之隐式类型转换"时,请将那些函数定义为 "class template内部的 friend 函数"。
示例:
template
class Rational{
public:
Rational(const T &numerator = 0, const T &denominator = 1) // Item 20 对于自定义类型以passed by referenc...
分类:
编程语言 时间:
2014-07-14 13:52:39
阅读次数:
173
经验:多重继承比单一继承复杂。它可能导致新的歧义性,以及对 virtual 继承的需要
示例:
class BorrowableItem{
public:
void checkOut();
};
class ElectronicGadget{
private:
bool checkOut() const;
};
class MP3Player:
public BorrowableItem
public ElectronicGadget
{...};
MP3Player mp;
mp.checkOut...
分类:
编程语言 时间:
2014-07-14 13:38:11
阅读次数:
240
经验:可在derived class templates 内通过 "this->" 指涉 base class templates 内的成员名称,或藉由一个明白写出的 "base class 资格修饰符"完成。
示例:
class CompanyA{
public:
//...
void sendCleartext(const std::string &msg);
void sendEncrypted(const std::string &msg);
//...
};
class Company...
分类:
编程语言 时间:
2014-07-14 13:20:25
阅读次数:
263
//判断文件是否存在
bool FileExistsW(const wstring &fn)
{
WIN32_FIND_DATAW fd;
HANDLE hFile = FindFirstFileW(fn.c_str(),&fd);
if (hFile != INVALID_HANDLE_VALUE)
{
::FindClose(hFile);...
点击打开链接
题意:有n条村落连接线路,给你m个草儿附近的村落,在给出t个草儿想去的地方。从草儿附近的村落出发到她想去的地方所有线路中的花费时间最少的一个。
解析:多源多点最短路,暴力枚举
#include
#include
#include
using namespace std;
const int maxn = 1005;
const int Max = 0xfffffff;
i...
分类:
其他好文 时间:
2014-07-14 12:57:00
阅读次数:
214
经验:声明 template 参数时,前缀关键字 class 和 typename 可互换。请使用关键字 typename 标识嵌套从属类型名称;
示例1:
template
void print2nd(const C &container){
C::const_iterator *x;//歧义。如果const_iterator是个static成员变量,x是个global 变量,这里的 *就是乘
//...
}
示例2:
template
void pr...
分类:
编程语言 时间:
2014-07-14 11:06:02
阅读次数:
206