`
yanlijun250
  • 浏览: 783298 次
文章分类
社区版块
存档分类
最新评论
文章列表
/* * *Declaration:The author of <<Accelerated C++>> has wrote in the end of that book: As you look for reading materimal, keep in mind that books on the shelf do not make you a better programmer. Ultimately, the only way to improve your programming is to write programs. >这些程序来自一些ACM书籍, ...
问题定义:从n个数中,等概率的抽取m个数。 真心觉得自己概率论学得不咋第。第一个和第三个函数还是没有看懂。 #include <iostream> #include <algorithm> #include <set> #include <stdlib.h> using namespace std; void genknuth( int m, int n) { srand(5); for( int i = 0; i < n; i++) if( (rand() % (n - i) < m)) { cout < ...
map是一个映射命令,将常用的很长的命令映射到一个新的功能键上。 map的格式: map <要映射键> <被映射的按键序列>,比如 map T :q!后,则在命令模式下按T并按回车,就会退出vim vmap 和map类似,二者的区别在于前者用于所谓的Visual模式,后者用于通常的命令模式。 映射 :map <F2> ggvG 解除映射 :unmap <F2> 清除所有映射 :mapclear 在光标后面插入当前日期和时间 :map <F2> a<C-R>=strftime(" ...
当我们使用vim进行一些高级时,发现每次都需要进行相应的设置(如:这次设置了缩写 ab #i #include ,下次使用就不行了,还得再次设置,非常不爽)vim不会为我们保存这些个性化的设置,需要我们自行修改配置文件。 这篇博客主要讨论vim的配置文件,使其能保存我们的一些个性化设置。其实设置也很简单,只是初学者对此毫无头绪,而且,想用搜索引擎解决这个问题,又不知到该输入什么关键字。作者查阅了《鸟哥的linux私房菜》,见第三版第十章 288页。有这么一句话:我们可以通过配置文件来直接规定我们习惯的vim操作环境。整体的vim的设置值一般是放置在/etc/vimrc这个文件中 ...
This is a program to generate a cross-reference table that indicated where each word occurs in the input. Here is the program( I think this is a good example to illustrate the subject which is modern of c++ design of this book: #include<iostream> #include<fstream> #include<map> ...
堆排序的关键是要实现siftup和siftdown。当建立完这两个函数以后,排序一个数组只需要5行代码。算法执行了n-1次siftup和siftdown,而每次操作的成本最多O(lgn),所以运行时间为O(nlogn)。 #include <stdio.h> #include <stdlib.h> #define MAX 20 void swap( int *data, int i, int j) { int temp = data[i]; data[i] = data[j]; data[j] = temp; } //siftup比较好理解, ...
以前学数据结构的时候,学到后面一些抽象一点的数据结构,老师也不让我们写代码,也没有强调这些东西的重要性。再加上那时候不懂事,都没有具体去实现过堆,总认为这是很复杂的东西,其实学会以后真是简单的不得了,而且是又简单,又好用。#include<iostream> #include<stdlib.h> #include<stdio.h> using namespace std; template<class T> class priqueue{ private: int n,maxsize; T *x; void swap( int i ...
这几天对vim的学习就快到了狂热的地步,简直忘了学习vim是为了编程,没有办法,就是喜欢,就是希望这种狂热的感觉。 缩写(abbreviations): 缩写在插入,替换和命令行模式中使用。如果你输入一个是缩写的单词,它会被替换成所表示的东西。这可以在经常输入的长单词时节省键击。并且能用它来自动更正经常犯的拼写错误。例如: :iab ms Microsoft :iab tihs this( iab 与 ab一样,只是仅限于在插入模式下使用,在本文中,默认iab=ab)不能被缩写的字串例子:"a.b", "#def","a b" ...
问题定义: 给定一个输入文本文件,查找其中最长的重复子字符串。例如,"Ask not what your country can do for you, but what you can do for you country"中最长的重复字串就是"can do for you","your country"是第二长的重复字串。如何编程找出最长的重复字串?如何找出出现次数超过M的重复字串? 示例1,从控制台输入: #include<stdio.h> #include<string.h> #defi ...
标准库提供的bitset类简化了位集的处理。bitset其实很简单,只是因为它不如vector和string那样常用,所以很多人都放弃了这么好用的工具。 头文件:#include<bitset> 常用的成员函数: b.any() b中是否存在置为1的二进制位? b.none() b中不存在置为1的二进制位吗? b.count() b中置为1的二进制位的个数 b.size() b中二进制位数的个数 b[pos] 访问b中在pos处二进制位 b.test(pos) b中在pos处的二进制位置为1么? b.set() 把b中所有二进制位都置为1 b.set( ...
用C++的bitset实现非常的方便: /************* 位图排序算法实现 *************/ #include <iostream> #include <bitset> #include <fstream> using namespace std; int main() { // 查看bitset的实现可知bitset是利用对unsigned long进行位运算间接实现对位的存储的 // 如是保存一个32位的bitset实质是保存了4个unsigned long长整数 bitset<1000000> b; b. ...
#include<iostream> #include<string.h> #include<stdio.h> #include<algorithm> using namespace std; const int MAX = 100000; void swap( int *data, int i, int j) { int temp = data[i]; data[i] = data[j]; data[j] = temp; } void InsertSort3( int *data, int n) { int i, j, temp; f ...
一步一步优化的快速排序,速度比插入排序快很多,而且可以很方便的引入随机算法来避免最差情况。 #include<iostream> #include<string.h> #include<stdio.h> #include<algorithm> using namespace std; const int MAX = 1000000; void swap( int *data, int i, int j) { int temp = data[i]; data[i] = data[j]; data[j] = temp; } void In ...
这么简单的插入排序,都可以优化,还有什么是不可以优化的。最让我惊讶的是,当多次调用一个函数的时候,函数的调用开销是不可忽略的。正如测试结果所示: #include<stdio.h> #define MAX 1000000 void swap( int *data, int i, int j) { int temp = data[i]; data[i] = data[j]; data[j] = temp; } //未经过优化的插入排序,简单直观 void InsertSort1( int *data, int n) { int i, j; for( i = 1; i< ...
因为之前对syncronized方法的错误理解,最近犯了一个很严重的错误,以此文记。 错误理解:synchronized方法仅对此同步方法加锁,只是这个方法不能被多个线程同步执行。 正确理解:synchronized方法对整个实例内所有synchronized 方法加锁,一个实例内所有的synchronized方法不能被同步执行。 ---------- 参考:1、笔试:当一个线程进入一个对象的一个synchronized方法后,其它线程是否可进入此对象的其它方法? ?
Global site tag (gtag.js) - Google Analytics