
C++
文章平均质量分 52
Java_beginer1
爱好算法
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
归并排序C++实现
归并排序原创 2013-11-05 23:36:56 · 792 阅读 · 0 评论 -
http://poj.org/problem?id=1657&&Distance on Chessboard
象:在同一斜线上,一步可以到达,不在同一斜线上,如果两点颜色相同两步可达,否则不可达; #include #include #include #include #include #include #include #include #include #include using namespace std; const int N=100015; bool map[9][9]; int ma原创 2012-10-02 20:59:33 · 812 阅读 · 0 评论 -
月老的难题&&二分图最大匹配模板&&http://acm.nyist.net/JudgeOnline/problem.php?pid=239
二分图最大匹配:用邻接矩阵超时,需要用邻接表; #include #include #include #include #include #include using namespace std; const int N=512; bool chk[N]; vectorvis[N]; int n; int xM[N],yM[N]; bool SearchPath(int u) { int dd原创 2012-09-29 21:09:25 · 1240 阅读 · 0 评论 -
POJ1330&&LCA最近公共祖先模板
在这我用的是tarjan搞的:tarjan的话需要知道树的根节点,这题没说,但是可以根据入度等于0,判断根节点;tarjan的主要思想是DFS和并查集; tarjan:有待补充 #include #include #include #include #include #include #include #include #include #include using na原创 2012-09-30 17:59:31 · 904 阅读 · 0 评论 -
http://poj.org/problem?id=2187
#include #include #include #include #include using namespace std; #define N 50005 const double Pi = acos(-1.0); struct Point { int x,y; }P[N],S[N]; int n,top,L; int Dis(const Point& p1,const P原创 2012-09-06 09:25:30 · 1057 阅读 · 0 评论 -
C++中的static
在定义变量和函数时用关键字static用来修饰命名空间作用域的变量和函数时和extern的作用刚好相反; extern用法 但是这种方式在2003的c++ 2.0标准中已经宣布不再鼓励这种方式; 用的是匿名的命名空间,尼玛我是第一次听说这个匿名的命名空间,它是这样的; namespace{ int n; void f(){ n++; }原创 2012-08-17 19:05:10 · 1312 阅读 · 0 评论 -
C++自己写的非常简单的文件
以后我的定位就是用linux下的C/C++开发,现在开始复习C++了,虽然以前学过,而且自己在大一的第二学期就已经学了一点点,但是那都是皮毛,去年暑假学了一点点STL,自我感觉还不错,结果在大二第一学期的C++考试考得很烂,自己大二第一学期完全没有学到神马东西,虽说学了一点点的算法,但是还是很弱的; 头文件声明 //头文件声明 #ifndef SALE_H #define SALE_H c原创 2012-08-17 19:42:58 · 1166 阅读 · 0 评论 -
C++ extern 关键字的用法
extern声明一个外部变量与外部函数: //源文件1 int i; //源文件2 extern int i;//声明一个在其他文件中定义的外部变量i;如果不写这个extern int i;源文件2是不能用文件1中的变量i的; 外部函数是在所有类外声明的函数(非成员函数),都是具有命名空间作用域的,如果没有特殊说明,这样的函数都可以在不同的编译单元中被调用,只要在调用之前有引用性声明即可,也可以在原创 2012-08-17 18:51:41 · 1237 阅读 · 1 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1698&&线段树 成段替换 延迟标记
ORZ #include #include using namespace std; const int N=100005; int num[N<<2],col[N<<2]; #define lson l, mid, rt << 1 #define rson mid+1, r, rt << 1 | 1 void PushUp(int rt) { num[rt]=num[rt<<1]+num[r原创 2012-08-01 18:31:56 · 721 阅读 · 0 评论 -
http://lightoj.com/volume_showproblem.php?problem=1059最小生成树变形
利用kruscal求最小生成树,如果建一条路的费用超过建一个机场,就去掉该边(这点很关键); #include #include #include using namespace std; const __int64 N=10002; const int INF=9999999999; struct node { __int64 u,v; __int64 cost; }a[N*10]; __原创 2012-07-31 19:08:36 · 1224 阅读 · 1 评论 -
hdu1596floyd就能过数据太水
#include #include #include #include #include using namespace std; const int N=1002; const double INF=99999.0; double Map[N][N]; int n; int main() { while(~scanf("%d",&n)) { for(int原创 2012-07-30 19:44:39 · 664 阅读 · 0 评论 -
2012多校联合2&&1001 hero 贪心
刚开始排序时有问题;后来看到楼长的解题告,感觉和我的思想一样;我的还要简单一些:结果由于排序的问题wa了好多次; #include #include #include #include #include using namespace std; const int N=21; struct node { long long x; long long y; }a[N]; boo原创 2012-07-28 16:21:10 · 739 阅读 · 0 评论 -
最小生成树prim算法hdu1879
本暑假集训第一次用prim写最小生成树;各种调试:最后发现多加一个边orz,只有我这种人才这样;码代码这么挫 这也算是最小生成树prim的模板吧: #include #include #include #include #include using namespace std; const int N=102; int dist[N]; int map[102][102]; const i原创 2012-07-26 17:10:52 · 842 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=1020大水题一个不解释
#include #include #include #include #include #include #include using namespace std; int main() { int t; scanf("%d",&t); string str; while(t--) { mapM; cin>>str; for(int i=0;i<str.si原创 2012-07-27 09:37:27 · 670 阅读 · 0 评论 -
POJ1470&&最近公共祖先
输入淡腾要死:纯粹模板 #include #include #include #include #include #include #include #include #include #include using namespace std; const int N=1005; int father[N]; vectorM[N],Q[N]; bool vis[N]; int n,in[N],a原创 2012-10-01 17:48:46 · 773 阅读 · 0 评论 -
2012 ACM/ICPC Asia Regional Tianjin Online && hdu4279 Number
进制转换转换为8进制;;; #include #include #include #include #include using namespace std; int main() { // freopen("1.txt","w",stdout); long n,x,ans=0,xx; while(~scanf("%ld",&n)&&n) { x=0; xx=n原创 2012-09-12 10:31:36 · 712 阅读 · 0 评论 -
堆排序
堆排序原创 2013-09-17 01:37:20 · 908 阅读 · 0 评论 -
C++虚函数
C++纯虚函数&&抽象类原创 2013-08-22 18:37:30 · 687 阅读 · 0 评论 -
c++虚函数
vtable原创 2013-08-22 19:24:54 · 745 阅读 · 0 评论 -
kmp&&hdu 1711 next数组
KMP原创 2013-08-21 13:47:29 · 677 阅读 · 0 评论 -
unix 网路编程(卷一)第一个程序编译过程
unix网络编程原创 2013-08-03 16:01:46 · 1102 阅读 · 0 评论 -
乱侃c++
就在刚才我感觉c++真的好复杂,函数重载,多态,虚函数,虚函数表,模版,继承等一大坨东西好恶心,c++既然完全支持C语言,当然是把它的优缺点统统接下了,C语言中指针本身并不太难,是C语言的精华,当年刚开始学习C时看到说,学不会指针C和没学一样,当时真是熬夜看我们系老师自己编的那本白皮书,看指针看的眼花,东西学的再多,长时间不用很快又会忘得,就像是记英语单词一回事,学了不用东西永远不是自己的。 指原创 2013-07-29 17:58:19 · 845 阅读 · 0 评论 -
C++&&Mysql&&codeblocks
#include #include #include #include using namespace std; /*数据库连接用宏*/ #define HOST "localhost" #define USERNAME "root" #define PASSWORD "333333" #define DATABASE "test" void query_sql(char* sql)原创 2013-06-22 21:19:54 · 1108 阅读 · 0 评论 -
各种字符串hash
unsigned int SDBMHash(char *str){ unsigned int hash = 0; while (*str) { // equivalent to: hash = 65599*hash + (*str++); hash = (*str++) + (hash << 6) + (hash << 16) - hash; }原创 2013-05-10 07:56:11 · 818 阅读 · 0 评论 -
根据算法导论写的快速排序
算法导论上面说在选取基准元素是取得最后一个,数据结构课本上面是取第一个; 不过没有原理都是一样的;通过Qartion(int a[],int l,int r)函数将数组a中元素划分为三部分,比a[r]小的,比a[r]大的,a[r]; 最后返回基准元素所在的位置; #include #include #include #include #include using name原创 2012-07-30 09:13:48 · 504 阅读 · 0 评论 -
给出一个n个元素的链表输出倒数第k个节点
用两个指针;初始化为头指针;用其中一个指针遍历链表,当该指针遍历到第k个节点时,另外一个指针开始从头节点开始遍历链表;两个指针之间的距离为k;遍历完链表时第二个指针所指向的节点就是倒数第K个: #include #include #include using namespace std; struct node{ int val; node *next; node(){原创 2012-10-26 19:57:42 · 1496 阅读 · 0 评论 -
hdu4267
郁闷死了,做了两天了, (i-a)%k==0,可以转化为i%k==a%k;ORZ... #include #include #include #include using namespace std; const int N=50010; int sum[N<<2][55]; int col[N<<2],res[N]; #define lson l,mid, rt << 1 #define原创 2012-09-20 17:40:04 · 787 阅读 · 0 评论 -
HDU3234
尼玛这题出题人太JB NB了,乍一看以为线段树,仔细看看发现不是,查询时区间不连续 后来就搜索解题报告,才知道是并查集 ,但是又不知道咋个并,咋个查。。。ORZ,,,,蒟蒻, 题意:给出一个数值固定的数列,x0,x1,x2,……xn-1; #include #include #include #include #include #include using namespace std原创 2012-10-05 18:16:24 · 908 阅读 · 0 评论 -
POJ 1986 LCA模板加强点的
题意算是见过的最龌龊的了,你妹的,都不知道一共有多少个顶点,RE几次后立马把数组开到10W级别的; #include #include #include #include #include #include #include #include #include #include using namespace std; const int N=100015; struct node {原创 2012-10-02 13:04:01 · 793 阅读 · 0 评论 -
http://poj.org/problem?id=1330&&大水货一个啊
LCA纯版题,各种调试不成功,砸电脑的心都有了;撞墙去了恶心死了; 更恶心的是vs2010报错:sbIDE #include #include #include #include #include using namespace std; const int MAX=10010; #define CLR(arr,val) memset(arr,val,sizeof(arr)) int n,f原创 2012-07-25 18:34:06 · 1182 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=2037贪心水题
尼玛被线段树完虐...暂时转战贪心 #include #include using namespace std; paira[100]; /*struct node {int first; int second;}a[100]; bool cmp(node a,node b) { return a.first<b.first; }*/ int main() { int n; w原创 2012-08-08 16:53:28 · 817 阅读 · 0 评论 -
http://acm.hdu.edu.cn/showproblem.php?pid=3371用C++能过,G++过不了不过用prim能过
#include #include #include #include #include #include using namespace std; class node { public: int u,v; int dist; }edge[55002]; int num[509]; int find(int x) { return x==num[x]?x:num[原创 2012-07-11 18:16:05 · 845 阅读 · 0 评论 -
http://lightoj.com/volume_showproblem.php?problem=1338字符串比较
水题一枚,刚开始时因为没用getchar(),导致悲催了,后来就行了;传送门 #include #include #include #include #include #include using namespace std; int main() { int t; scanf("%d",&t); getchar(); for(int k=1;k<=t;k++) { char原创 2012-07-11 10:12:00 · 592 阅读 · 0 评论 -
hdu1856并查集
#include #include using namespace std; int num[1000006],con[1000006]; bool vis[1000006]; int find(int x) { return x==num[x]?x:num[x]=find(num[x]); } int main() { int n; while(~scanf("%d",&n)) {i原创 2012-07-10 16:56:38 · 933 阅读 · 0 评论 -
http://poj.org/problem?id=2524并查集简单应用
用总人数减去合并的次数得到的就是所要求的: #include #include int num[50001]; int find(int x) { return x==num[x]?x:num[x]=find(num[x]); } int main() { int n,m,t=1; while(~scanf("%d%d",&n,&m)&&n+m) { for(int i=0;i<原创 2012-07-10 15:07:24 · 537 阅读 · 0 评论 -
SRM 549 div2 250pt
题意:在桌子上给出三个帽子和一个小球,刚开始不知道小球在那个帽子下面,然后给出交换次数每次交换只能交换相邻的两个帽子,小球和帽子一起移动(如果小球在该帽子下面),问最后小球的位置帽子编号【0,1,2】; 这次做TC再次ORZ。。。。。。。。。还是浩哥威武,题意一说一会就能搞ORZ。。。。#include #include #include #include #include #incl原创 2012-07-10 08:56:24 · 595 阅读 · 0 评论 -
强连通分量tarjan模板hdu1269迷宫城堡
第一次写强连通tarjan同时也是自己在hdu100题的记录 :在有向图中的强连通分量,核心是深搜,dfn[]数组记录搜索顺序,low[]数组所能返回的最小的点; #include #include #include #include using namespace std; vectorG[10003]; int dfn[10003],low[10003],ss[10003],top=1,mm原创 2012-07-09 15:18:21 · 781 阅读 · 0 评论 -
SRM211 div1 500pt 搜索应用
题意是给出400X600的矩阵,不断在矩阵400X600内划矩阵,第一次被划过的矩阵区域颜色改变,问的是经过多次划矩阵后,400X600矩阵内没有改变颜色的区域,连通区域的块数和连通区域大小,按照连通区域大小从小到大排序; 思路就是:每次划过的矩阵区域颜色改变(已经变过的不用改变);然后循环图;依次搜索颜色没变的点; 其中学到了把字符串转化为整数可以用 istringstream; #inc原创 2012-07-08 11:34:30 · 682 阅读 · 0 评论 -
求二叉树排序树后序,http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pro
要给这个水题ORZ。。。。。。。我真的是弱爆了,这个烂题耽误我快一下午。。。。我他妈的弱爆了。。。各种跪烂。。。上午TC的一题各种跪。。。。下午又是各种ORZ。。就是给出二叉排序树的先序遍历,求后序,,,,,对先序排下序就有中序了,,,各种OTL,,,其实直接建树就行。。。然后直接后序。。。#include //#include #include #include using namespace原创 2012-07-08 17:28:36 · 668 阅读 · 0 评论 -
并查集应用http://ac.nbutoj.com/Problem/view.xhtml?id=1187
并查集应用:ORZ。。。。无语了这一题写了快一下午,累的我要吐血了,浑身疼啊,,先是TLE,然后各种参考大神代码,尤其是骆神的。。。ORZ。。。。ORZ。。。 昨天比赛就是抱骆神大腿的,,,ORZ,骆神V587,ORZ......各种若斯。。。。#include #include #include using namespace std; struct node { int fa; bool原创 2012-07-07 18:40:04 · 990 阅读 · 0 评论