自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

黑眼圈的意志

初学者

  • 博客(42)
  • 收藏
  • 关注

原创 对于循环不变式证明的总结

对于循环不变式,必须证明它的三个性质:初始化:他在循环的第一轮迭代开始之前,应该是正确的保持:如果再循环的某一次迭代开始之前它是正确的,那么,在下一次迭代开始之前,它也应该保持正确终止:当循环结束时,不变式给了我们一个有用的性质,它有助于表明算法是正确的注明:当头两个性质成立时,你就能保证循环不变式在循环的每一轮迭代开始之前,都是正确的

2013-11-29 22:08:29 720

原创 INSERTION-SORT(A)的C++代码

书中伪代码:for j <- 2 to length[A] do key <- A[j] i <- j - 1 while i > 0 and A[i] > key do A[i+1] <- A[i] i <- i -1 A[i+1] 我的C++代码实现:void I

2013-11-29 22:03:42 543

原创 常用的时间复杂度排序

一些常用的时间复杂度排序:O(lgn) √n) 这里,我们默认lg始终是以2为底,符号“^”表示乘方的意思

2013-11-29 21:55:53 883

原创 《算法导论》学习

开始攀爬一座巨大的山峰——《算法导论》这个目录下包含一些书上的伪代码用C++实现的代码,还有书上的习题我自己做的解答因为我水平实在有限,如有错误,请各位一定要指出,谢谢大家了!

2013-11-29 21:49:14 630

原创 Exercise 3.4

#includeint main(){ using namespace std; cout << "Enter the number of seconds:"; long second; cin >> second; int minute,hour,day; minute = second / 60; second %= 60;

2013-11-29 21:38:39 494

原创 Exercise 3.3

#includeint main(){ using namespace std; const int rate = 60; cout << "Enter a latitude in degrees, minutes, and seconds:" << endl; cout << "First, enter the degrees:" float degr

2013-11-29 21:21:51 483

转载 Sample 3.14:typecast.cpp

#includeint main(){ using namespace std; cout.setf(ios_base::fixed, ios_base::floatfield); float tree = 3; int guess = 3.9832; int debt 7.2E12; cout << "tree = " << tree << e

2013-11-29 21:07:23 458

转载 Sample 3.13:assign.cpp

#includeint main(){ using namespace std; cout.setf(ios_base::fixed, ios_base::floatfield); float tree = 3; int guess = 3.9832; int debt 7.2E12; cout << "tree = " << tree << e

2013-11-29 21:03:09 411

转载 Sample 3.12:modulus.cpp

求模操作,求取余数#includeint main(){ using namespace std; const int Lbs_per_stn = 14; int lbs; cout << "Enter your weight in pounds: "; cin >> lbs; int stone = lbs / Lbs_per_stn;

2013-11-29 20:45:39 408

转载 Sample 3.11:divide.cpp

注意,当两个操作数全是整型的时候,是不能以ios_base::fixed, ios_base::floatfield方式显示小数点后六位#includeint main(){    using namespace std;    cout.setf(ios_base::fixed, ios_base::floatfield);    cout << "Integer div

2013-11-29 20:41:02 419

转载 Sample 3.10:arith.cpp

float类型运算结果取小数点后六位显示#includeint main(){ using namespace std; float hats,heads; cout.setf(ios_base::fixed, ios_base::floatfield); cout << "Enter a number: "; cin >> hats; c

2013-11-29 20:28:35 449

转载 Sample 3.8: floatnum.cpp

将浮点型数显示到小数点后6位,用的是ios_base::fixed和ios_base::floatfield#includeint main(){ using namespace std; cout.setf(ios_base::fixed,ios_base::floatfield); float tub = 10.0 / 3.0; double mint

2013-11-29 20:23:00 496

转载 Sample 3.9:fltadd.cpp

#includeint main(){ using namespace std; float a = 2.3E+22f; float b = a + 1.0f; cout << "a = " << a << endl; cout << "b - a = " << b - a << endl; return 0;}在科学计数法中,如果一个极大的

2013-11-29 20:16:19 436

原创 关于看C++ Primer Plus的建议

这本书事无巨细,虽然从水平上来说,并没有很高超的技巧,但是,是基础中的基础这本书不要仅仅想着看一、两遍就放那,一定要做到,所有的范例敲一遍,所有的习题自己做一遍!不要追求高速看完这本书,好菜慢慢吃,好书细细品。加油,奋斗!

2013-11-29 20:11:53 1875

原创 Exercise 3.2

#includeusing namespace std;int main(){ const int rate_inch_foot = 12; const float rate_inch_meter = 0.0254; const float rate_pound_kg = 2.2; cout << "Enter the foot your height:___

2013-11-28 22:53:35 443

原创 Exercise 3.1

#includeusing namespace std;int main(){ const int rate = 12; cout << "Enter the your height in inch:____\b\b\b\b"; int inch; cin >> inch; cout << "Your height is " << inch / rat

2013-11-28 22:44:54 384

转载 Sample 3.7: bondini.cpp

转义字符的使用,在cout中使用#includeint main(){ using namespace std; cout << "\aOperation \"HyperHype\" is now activated!\n"; cout << "Enter your agent code:________\b\b\b\b\b\b\b\b"; long cod

2013-11-27 21:20:32 497

转载 Sample 3.6:morechar.cpp

#includeint main(){ using namespace std; char ch = 'M'; int i = ch; cout << "The ASCII code for " << ch << " is " << i << endl; cout << "Add one to the character code:" << e

2013-11-27 21:14:32 457

转载 Sample 3.5:chartype.cpp

第一次使用char类型的范例#includeint main(){ using namespace std; char ch; cout << "Enter a character: " << endl; cin >> ch; cout << "Holla! "; cout << "Thank you for the " << ch

2013-11-27 20:56:46 408

转载 Sample 3.4:hexoct2.cpp

#includeint main(){ using namespace std; int chest = 42; int waist = 42; int inseam = 42; cout << "Monsieur cuts a striking figure!" << endl; cout << "chest = " << chest <<

2013-11-27 20:50:45 502

转载 Sample 3.3:hexoct.cpp

#includeint main(){ using namespace std; int chest = 42; int waist = 0x425; int inseam = 042; cout << "Monsieur cuts a striking figure!\n"; cout << "chest = " << chest << "

2013-11-27 20:44:04 563

原创 找出所缺的整数

某数组A[1...n]含有所有从0到n的整数,但其中有一个整数不在数组中。通过利用一个辅助数组B[0...n]来记录A中出现的整数,很容易在O(n)时间内找出所缺的整数。但如果A中的元素是以二进制表示的,我们所能用的唯一的操作就是取A[i]的第j位。第一种以十进制的代码,是利用一个辅助数组来进行计数,然后扫描辅助数组,从而来确定所缺少的数字:#includeusing name

2013-11-26 22:12:50 488

原创 混乱的日子

不知不觉大三了,从没上大学开始,就决心考研了。。。谁让自己高中不争气,唉~周末去新东方学英语,白天晚上的课,平时还要复习XXXXXXX,一堆东西啊。突然觉得自己前两年跟白过一样,啥也不会。。。大梦谁先觉?一场梦境把我折磨的死去活来,陷得真心深,无奈自己没有任何感情经验,估计以后就只有过上不断跑相亲场的日子了感时花溅泪,恨别鸟惊心。有梦大胆追吧,我错了好多好多,错过了ta,不知还能追

2013-11-26 00:01:31 500

转载 Sample 3.2:exceed.cpp

#include#define ZERO 0#includeint main(){ using namespace std; short sam = SHRT_MAX; unsigned short sue = sam; cout << "Sam has " << sam << " dollars and Sue has " << sue; cou

2013-11-25 23:55:22 460

转载 Sample 3.1:limits.cpp

#include#includeint main(){ using namespace std; int n_int = INT_MAX; short n_shor = SHRT_MAX; long n_long = LONG_MAX; cout << "int is " << sizeof(int) << " bytes." << endl

2013-11-25 23:26:57 400

原创 Exercise 2.6

#includeusing namespace std;void show(int h,int m){ cout << "Time:" << h << ":" << m << endl; return;}int main(){ cout << "Enter the number of hours:"; int hour,minute; cin

2013-11-25 23:18:09 349

原创 Exercise 2.5

#includeusing namespace std;float exchange(float l){ return l * 63240;;}int main(){ cout << "Enter the number of light years:"; float light,unit; cin >> light; unit = excha

2013-11-25 23:12:18 378

原创 Exercise 2.4

#includeusing namespace std;void exchange(float t){ cout << t << "degrees Celsius is " << 1.8 * t + 32.0 << " degrees Fahrenheit." << endl; return;}int main(){ cout << "Please ente

2013-11-25 23:05:49 538

原创 Exercise 2.3

#includeusing namespace std;void output1(){ cout << "Three blind mice" << endl; return;}void output2(){ cout << "See how they run" << endl; return;}int main(){ output1

2013-11-22 23:02:34 453

原创 Exercise 2.2

#includeint main(){ using namespace std; int lang; cout << "请输入浪的值:"; cin >> lang; cout << lang << "浪 = " << lang * 140 << "码" << endl; return 0;}

2013-11-22 22:27:06 466

原创 Exercise 2.1

#includeint main(){ cout << "我叫黑眼圈的意志,家住中国!" << endl; return 0;}

2013-11-22 22:07:25 518

转载 Sample 2.6:convert.cpp

函数的返回值的利用。#includeint stonetolb(int)int main(){ using namespace std; int stone; cout << "Enter the weight in stone:"; cin >> stone; int pounds = stonetolb(stone); cout <<

2013-11-22 22:03:41 603

转载 Sample 2.5:ourfunc.cpp

是一个调用自定义函数的例子。#includevoid simon(int);int main(){ using namespace std; simon(3); cout << "Pick an integer:"; int count; cin >> count; cimon(int); cout << "Done!" << e

2013-11-22 21:53:21 785 1

原创 ex2_2 棋盘上的距离

问题描述国际象棋的棋盘是黑白相间的 8 * 8 的方格,棋子放在格子中间。王、后、车、象的走子规则如下: 王:横、直、斜都可以走,但每步限走一格。 后:横、直、斜都可以走,每步格数不受限制。 车:横、竖均可以走,不能斜走,格数不限。 象:只能斜走,格数不限。写一个程序,给定起始位置和目标位置,计算王、后、车、象从起始位置走到目标位置所需的最少步数。

2013-11-22 21:05:29 976

转载 Sample 2.4:sqrt.cpp

第一次引用了函数,还是cmath库里的库函数 sqrt( ),开方用的#include#includeint main(){ using namespace std; double area; cout << "Enter the floor area, in square feet, of your home:"; cin >> area;

2013-11-21 21:42:01 680

转载 Sample 2.3:getinfo.cpp

第一次涉及到输入的范例#includeint main(){ using namespace std; int carrots; cout << "How many carrots do you have?" << endl; cin >> carrots; cout << "Here are two more."; carrots =

2013-11-21 21:35:55 618

转载 Sample 2.2:carrot.cpp

这个只是说输出其实可以分段或者合并的#includeint main(){ using namespace std; int carrots; carrots = 25; cout << "I have"; cout << carrots; cout << " carrots."; cout << endl; carro

2013-11-21 21:30:11 670

转载 Sample2.1:myfirst.cpp

好久没有复习基础了,再看了一遍C++ Primer Plus ,感觉不一样了很多。这次再看,决心把书上所有的范例和习题敲一遍。#includeint main(){ using namespace std; cout << "Come up and C++ me come time." ; cout << endl; cout << "You won't

2013-11-21 21:26:30 736

原创 自己编的猜数字小游戏

自己撸了半个小时的代码采编出来的一点点东西。。。输入考虑不足,当输入字符时,就会崩溃。。。#include#include#includeusing namespace std;typedef struct model{ int num[4] = {0,0,0,0}; int answer[4] = {0,0,0,0}; int flag;}model;

2013-11-21 20:50:28 968

原创 ex2_1 鸡兔同笼问题

问题描述一个笼子里面关了鸡和兔子(鸡有2 只脚,兔子有4 只脚,没有例外)。已经知道了笼子里面脚的总数a,问笼子里面至少有多少只动物,至多有多少只动物?思考过程呃,这个问题思考的时候我居然首先是想用枚举法。想用for循环从1开始,然后列举出所有的鸡兔数量的可能性。但后来发现,自己一个兔子不是就是相当于两只鸡吗?于是就发现其实不用一一枚举计算,题目中只是要求最多或最少的动物,并没

2013-11-20 17:54:09 1266

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除