随笔 - 62  文章 - 96  trackbacks - 0
<2025年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

常用链接

留言簿(7)

随笔分类(66)

随笔档案(62)

文章分类(31)

文章档案(32)

友情链接

最新随笔

积分与排名

  • 积分 - 234754
  • 排名 - 108

最新评论

阅读排行榜

评论排行榜

转自:http://www.blog.edu.cn/user2/sempr/archives/2006/1142716.shtml
#include<cstdio>
const int MAX = 10000; int a[MAX],b[MAX]; int change; void merge(int p, int q, int r) { int i, j = 0; int begA = p, endA = q, begB = q+1, endB = r; while(begA <= endA && begB <= endB) { if(a[begA] <= a[begB]) b[j++] = a[begA++]; else { b[j++] = a[begB++]; change += q - begA + 1; } } while(begA <= endA) b[j++] = a[begA++]; while(begB <= endB) b[j++] = a[begB++]; for(i = 0; i < j; i++) a[p+i] = b[i]; } void mergeSort(int first, int last) { if(first < last) { int mid = (first + last) / 2; mergeSort(first, mid); mergeSort(mid+1, last); merge(first, mid, last); } } int main() { return 0; }
posted @ 2006-10-11 00:27 beyonlin 阅读(1060) | 评论 (0)编辑 收藏
d[i]用来保存起始点beg到点i的最短路径。
c[i][j]为边<i,j>的权。
如果边<i,j>不存在,则置c[i][j]=INF。
path[i]用来保存最短路径中点i的前一个顶点。
#include<cstdio>
const int MAX = 10000;
const int INF = 1000000;
int d[MAX];
int c[MAX][MAX];
bool flag[MAX];
//int path[MAX];
int Dijkstra(int beg, int n)
{
	int i, j, u, tmp;
	for(i = 1; i <= n; i++)
	{
		d[i] = c[beg][i];
		flag[i] = false;
		/*if(d[i] == INF)
			path[i] = 0;
		else
			path[i] = beg;*/
	}
	d[beg] = 0; flag[beg] = true;
	for(i = 1; i <= n; i++)
	{
		tmp = INF; u = beg;
		for(j = 1; j <=n; j++)
		{
			if(!flag[j] && d[j] < tmp)
			{
				u = j; 
				tmp = d[j];
			}
		}
		flag[u] = true;
		for(j  = 1; j <= n; j++)
		{
			if(!flag[j] && c[u][j] < INF)
			{
				if(d[u] + c[u][j] < d[j])
					d[j] = d[u] + c[u][j];
				//path[j] = u;
			}
		}
	}
	return 0;
}
int main()
{	
	return 0;
}
posted @ 2006-10-10 00:22 beyonlin 阅读(3809) | 评论 (0)编辑 收藏
d[i][j]保存边<i,j>的权。
如果边<i,j>不存在,则置d[i][j]为INF。
#include<cstdio>
const int MAX=10000; const int INF=1000000; int d[MAX][MAX]; int floyd (int n) { for(int k =1 ; k <= n; k++) { for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { if(d[i][k] + d[k][j] < d[i][j]) d[i][j] = d[i][k] + d[k][j]; } } }
        return 0; } int main() { return 0; } floyd后,如果d[i][j]>=INF,则点i到点j没有路。
else点i到点j的最短路径长度为d[i][j]。
posted @ 2006-10-09 00:15 beyonlin 阅读(1608) | 评论 (0)编辑 收藏

最近发现自己对数论几乎是一窍不通。
是时候开始学了。
从零开始……
判断一个数是否为质数:

bool prime(int a)
{
	for(int i=2;i<=sqrt(a);i++)
	{
		if(a%i==0)
			return false;
	}
	return true;
}
posted @ 2006-10-08 00:40 beyonlin 阅读(855) | 评论 (2)编辑 收藏

转载自:http://www.cppblog.com/zerolee/archive/2006/09/12/12335.html

增添于网上的一些书单:

C++/OPP/OOD系列:
层级一:语法/语意(C++)
[Lippman2000] Essential C++
Essential C++,by Stanley B. Lippman Addison Wesley Longman 2000,276 pages
Essential C++ 中文版 ,侯俊杰 译,282页

[Andrew Koeing & Barbara MOO] Accelerated C++
Accelerated c++, Andrew Koeing & Barbara MOO, Addison Wesley, 2000

[Eckel2000] Thinking in C++
Thinking in C++ 2/e Bruce Eckel 2000 1470 pages Prentice Hall
C++ 编程思想,刘宗田等 译,420页

[Lippman98] C++Primer
C++ Primer,3rd Editoin,by Stanley Lippman and Josee Lajoie
Addison Wesley Longman,1998 1237 pages
C++ Primer 中文版,侯俊杰 译,1999,1237页

[Struostrup2000] The C++ Programming Language
The C++ Programming Language,Special Editoin,by Bjarne Stroustrup
Addison Wesley Longman,2000,1017 pages

[ANSI C++] C++规格书 1998.9.1 PDF格式
ANSI C++ 1996 Draft


层级二:专家经验(C++/OOP)
[Meyers96] More Effective C++
More Effective C++, by Scott Meyers,Addison Wesley,1996,318pages
More Effective C++中文版,侯俊杰,培生 2000. 318页

[Meyers98] Effective C++
Effective C++, Second Edition,by Scott Meyers,Addison Wesley Longman,1998.256pages
Effective C++ 2/e 中文版,侯俊杰,培生 2000.256页
Effective C++, Third Edition, by Scott Meyers, Addison Wesley Longman.

[Sutter99] Exceptional C++
Exceptional C++,by Herb Sutter,Addison Wesley Longman,2000.208pages
Exceptional C++中文版,侯俊杰,培生 2000.248页

[Sutter2001]More Exceptional C++
More Exceptional C++ by Herb Sutter, Addison Wesley Longman, 2001.

[Sutter2004]Exception C++ Style
Exception C++ Style by Herb Sutter, Addison Wesley Longman, 2004.

层级三:底层机制(C++ Object Model)
[Ellis90] The Annotated C++ Reference Manual
The Annotated C++ Reference Manual,by Margaret A.Ellis and Bjarne Stroustrup
Addison Wesley Longman,1990,447 pages.

[Lippman96] Inside the C++ Object Model
Inside the C++ Object Model,by Stanley Lippman,Addison Wesley Longman,1996,280pages
深度探索C++物件模型,侯俊杰 译

层级四:设计观念的复用(C++/Patterns)
[Gamma95] Design Patterns:Elements of Reusable Object Oriented Software,
by Erich Gamma,Richard Helm,Ralph Johnson,and John Vlissides,Addison Wesley,1995.395pages
设计模式,李英军等译,机械工业出版社,2000.254页

[Alex2001]Modern C++ Design: Generic Programming and Design Patterns Applied
by Andrei Alexandrescu,Addison-Wesley,2001,352Paper


Genericity/STL系列(与层级二同步):
第一个境界是使用STL:
[Josuttis99]:The C++ Standard Library -A Tutorial and Reference,by Nicolai M.Josuttis,
Addison Wesley 1999.799pages

第二个境界是了解泛型技术的内涵与STL的学理:
[Austern98]:Generic Programming and the STL -Using and Extending the C++ Standard
Template library,by Matthew H.Austern,Addison Wesley 1998.548page


第三个境界是扩充STL:
[Stepanov2001]:C++ Standard Template Library by P.J.Plauger,Alexander A.Stepanov,
Meng Lee,David R.Musser,Prentice Hall 2001

其他书目
1. Large-scale C++ software Design, John Lako, Addison Wesley, 1996
2. Effective STL, Scott Meyers, Addison Wesley, 1995
3. C++ FAQs, 2nd, Marshall Cline, Greg Lomow, Mike Girou, Addison Wesley, 1998
4. C++ Gotchas, Stephen Dewhurst, Addison Wesley, 2002
5. C++ templates, the complete Guide, Daveed Vandevoorde & Nicolar M.Josuttis, Addison Wesley, 2002
6. Standard C++ iostreams and Locals, Angelika Langer & Klaus Kreft, Addison Wesley, 2000
7. Design & Evolution of C++, BS, Addison Wesley, 1994
8. Modern C++ Design, Andrie Alexandrescu, Addison Wesley, 2001
9. Generative Programming, Krzysztof Czarnecki & Ulrich Eisencecker, Addison Wesley, 2000
10.Pattern-oriented software architecture, Vol1:A system of patterns, Frank Buschmann, 1996
11. STL 源码剖析,侯杰
12. C++ Coding Standards 101 Rules Guidelines, Andrie Alexandrescu & Herb Sutter, Addison Wesley, 2005

posted @ 2006-09-21 00:13 beyonlin 阅读(516) | 评论 (0)编辑 收藏
仅列出标题
共12页: 1 2 3 4 5 6 7 8 9 Last