摘要: 转载自:http://blog.csdn.net/coder_xia/article/details/74478221、关于构造函数1)用构造函数确保初始化对于一个空类[cpp]view plaincopyclassEmpty{};编译器会自动声明4个默认函数:构造函数,拷贝构造函数,赋值函数,析构函数(当然,如果不想使用自动生成的函数,就应该明确拒绝),这些生成的函数都是public且inline。构造函数对数据成员进行初始化,使用未初始化值可能导致无法预知的错误,所以,确保每一个构造函数都将每一个成员初始化。2)为什么构造函数不能有返回值如果有返回值,要么编译器必须知道怎么处理返回值,要么 阅读全文
posted @ 2012-12-08 22:27 一把刷子 阅读(872) 评论(0) 推荐(0) 编辑
摘要: sizeof()是一个操作符,不是函数。#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int main(){ int a=printf("a")<<endl; cout<<a<<endl; cout<<sizeof(printf("abc"))<<endl;} 阅读全文
posted @ 2012-12-08 22:18 一把刷子 阅读(120) 评论(0) 推荐(0) 编辑
摘要: "********************************************" _vimrc/_gvimrc for windows" BY Douboer"********************************************"" echo "loading _vimrc ... ""set nocompatiblesource $VIMRUNTIME/vimrc_example.vimsource $VIMRUNTIME/mswin.vimbehave mswinset 阅读全文
posted @ 2012-10-30 23:00 一把刷子 阅读(297) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4081解题报告:先求最小生成树,并把这棵树记录下来,用low,和pre数组然后dp数组表示最大边,这个信息可以在求prim的时候得到。然后不断枚举任意两点修魔法路。那么这条路可能在最小生成树上,或者不在。如果不在则替换到这两点之间的在mst上的最长路。dp数组如果在咋直接替换到mst上的路 也是dp数组View Code #include<iostream>#include<string.h>#include<stdio.h>#include<algorithm> 阅读全文
posted @ 2012-10-24 23:55 一把刷子 阅读(172) 评论(0) 推荐(0) 编辑
摘要: View Code #include<iostream>#include<string.h>#include<stdio.h>#include<algorithm>#include<map>#include<string>using namespace std;const int maxn=10000;int num[maxn];map<string,int>node1;map<int,string>node2;int main(){ int n; while(scanf("%d" 阅读全文
posted @ 2012-10-21 22:52 一把刷子 阅读(146) 评论(0) 推荐(0) 编辑
摘要: View Code #include <time.h>#include <stdlib.h>#include <stdio.h>int main(){ int i,j; char ss[6]; srand((unsigned)time(NULL)); for(i=1;i<=30;i++) { for(j=0;j<6;j++) { int temp=rand(); temp=temp%10; if(temp<=3) ss[j]=temp+48; ... 阅读全文
posted @ 2012-10-20 23:41 一把刷子 阅读(319) 评论(0) 推荐(0) 编辑
摘要: http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2081解题:很暴力的spfa压线过了。。View Code #include<iostream>#include<cstdio>#include<algorithm>#include<vector>#include<queue>#include<cstring>#define maxn 2500 阅读全文
posted @ 2012-10-05 21:43 一把刷子 阅读(227) 评论(0) 推荐(0) 编辑
摘要: http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3736解题:题目理解很关键。。因为只有两种颜色。。所以二进制枚举。。。 如果出现某一个集合只有一种颜色(全为0,或者全为1)返回false,否则返回true。。蛋疼的是读入。。蛋碎了一地。。用了stringstream搞定http://www.cppblog.com/Sandywin/archive/2007/07/13/27984.htmlView Code #i 阅读全文
posted @ 2012-10-05 21:35 一把刷子 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 转自:http://www.cppblog.com/Sandywin/archive/2007/07/13/27984.htmlC++标准库中的<sstream>提供了比ANSI C的<stdio.h>更高级的一些功能,即单纯性、类型安全和可扩展性。在本文中,我将展示怎样使用这些库来实现安全和自动的类型转换。为什么要学习如果你已习惯了<stdio.h>风格的转换,也许你首先会问:为什么要花额外的精力来学习基于<sstream>的类型转换呢?也许对下面一个简单的例子的回顾能够说服你。假设你想用sprintf()函数将一个变量从int类型转换到字符串 阅读全文
posted @ 2012-10-05 20:54 一把刷子 阅读(440) 评论(0) 推荐(0) 编辑
摘要: http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3734解题 :暴力枚举,二进制枚举状态。。View Code #include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#define inf ~0U>>1using namespace std;int n,m;const 阅读全文
posted @ 2012-10-05 00:43 一把刷子 阅读(203) 评论(0) 推荐(0) 编辑