书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!

上一页 1 2 3 4 5 6 7 8 9 10 ··· 19 下一页

2012年4月19日

C++ 函数重载

摘要: 两个以上的函数,具相同的函数名,但是形参的个数或者形参的类型不同,编译器根据实参的类型及实参的个数最佳匹配,自动确定调用哪一个函数,这就是函数的重载。1>. int add(int a, int b) {}2>. int add(int a, int b, int c) {}3>. float add(float a, float b) {}三个add函数,具体用哪个一个重载要做的事情了。 阅读全文

posted @ 2012-04-19 19:46 More study needed. 阅读(137) 评论(0) 推荐(0) 编辑

C++ inline的使用

摘要: 内联函数不是在调用时发生控制转移,而是在编译时将函数体嵌入在每一个调用处。这样就节省了参数传递、控制转移等开销。View Code #include "iostream"#include "string"using namespace std;inline void print(string Str){ cout<<Str<<endl;}int main(){ string Str; while(cin>>Str) print(Str);} 阅读全文

posted @ 2012-04-19 19:37 More study needed. 阅读(163) 评论(0) 推荐(0) 编辑

打表打表何谓打表?

摘要: View Code #include<iostream>using namespace std;int main(){ freopen("God.txt","w", stdout); for(int i=0; i<10000; i++) { cout<<i<<","; if(i%30==0 && i!=0) cout<<endl<<endl; }}上面的freopen就是用来打表的了。无语呀,到现在才明白。第一个一定是:“文件名.txt”类似的。第二个一 阅读全文

posted @ 2012-04-19 18:44 More study needed. 阅读(382) 评论(0) 推荐(0) 编辑

2012年4月11日

TopoSort(拓扑排序)

摘要: 其实说白了,拓扑排序就是一个广度优先搜索。拓扑排序的方法如下: (1)从有向图中选择一个没有前驱(即入度为0)的顶点并且输出它. (2)从网中删去该顶点,并且删去从该顶点发出的全部有向边. (3)重复上述两步,直到剩余的网中不再存在没有前趋的顶点为止.本题目是采用的邻接表存储方法。具体的实现是用vector数组。题目:HDU 1285http://acm.hdu.edu.cn/showproblem.php?pid=1285View Code #include "iostream"#include "vector"#include "queue 阅读全文

posted @ 2012-04-11 18:36 More study needed. 阅读(940) 评论(0) 推荐(0) 编辑

2012年4月5日

欧几里德算法求最大公约数

摘要: 在求两个数的最大公约数方法中,辗转相除法是比较快的一种方法。也就是著名的欧几里德方法。View Code int Gcd(int a, int b){ return b==0?a:gcd(b, a%b);}View Code #include "iostream"#include "cstdio"#include "cstring"#include "string"#include "algorithm"using namespace std;int Gcd(int a, int b)//殴几里 阅读全文

posted @ 2012-04-05 16:48 More study needed. 阅读(194) 评论(0) 推荐(0) 编辑

2012年3月31日

感悟线段树

摘要: 其实线段树的数据结构没什么可说的,但是怎么用好它就有得说了。具体的来说就是:首先就是有段关系了,这个是第一位的。接着就是有大小关系了,这个是第二位的。再者就是数据量大,这个是次要的。只要满足了这三个条件,就是用线段树的时候了。如何理解段呢?比如说让你统计小于200的数据有多少个。这个就是段了。至于大小就是小于200的200了。(1)1 3 2 4 5 63 563 23 46 56 23 455 …… 888 这个例子是落在888以前的。(2)当然还是段中段,这个就不解释了。下面来贴出一道相关的题目。http://acm.swust.edu.cn/oj/contest/29/825/View 阅读全文

posted @ 2012-03-31 22:44 More study needed. 阅读(300) 评论(0) 推荐(0) 编辑

将数字字符串转化成整型数据

摘要: 将数字字符串转化成整型数据我们将用到两个函数。1. c_str它的作用是将string对象转化成char*,为什么要这样做呢,这就要说起另外一个函数了。2.atoi (它是array to integer的缩写)它的作用是将数字字符串转化成整型数据。但是要注意atoi(const char * s), 这个是它的标准用法,如果是atoi(string s)这个就不行了。具体的用法是。View Code string str="-1234";int num = atoi(str.c_str());string str = "1234";int Num = 阅读全文

posted @ 2012-03-31 10:00 More study needed. 阅读(705) 评论(0) 推荐(0) 编辑

2012年3月29日

字符串啊字符串

摘要: No.1:用C++输入带空格的字符串, getchar()必不可少。cin>>n;getchar();while(n--) getline(cin, s);No.2:不可对string s, char *s, char s[100] 像这种的串一个字符一个字符的赋值, 会出现烫烫烫啊。但是可以对char s[100]={0}这样的字符赋值。 阅读全文

posted @ 2012-03-29 22:39 More study needed. 阅读(162) 评论(0) 推荐(0) 编辑

2012年3月28日

DFS解决任意组合原来这样简单

摘要: HDU 2660http://acm.hdu.edu.cn/showproblem.php?pid=2660题意就不说了,直接走代码。View Code #include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespace std;#define max(a, b) (a>b?a:b)int V[21], W[21], Ans, N, K, L, i;void DFS(int p, int vv, 阅读全文

posted @ 2012-03-28 18:45 More study needed. 阅读(202) 评论(0) 推荐(0) 编辑

简单多重背包(每种物品选一次)

摘要: 先说一下多重背包问题。他是由完全背包而来的,但是不同的是,他的每件物品有一定的数量限量,而完全背包中每种物品可以有无限件。HDU 2660http://acm.hdu.edu.cn/showproblem.php?pid=2660题目大意:在N件物品中,最多可以选择K,在选择的K件物品中,总容量不能超过W.求选择的最大价值。本题就是一个任意组合问题了,当然除了这种解法以外还有一种解法。那就是DFS了。View Code #include<iostream>#include<cstdio>#include<cstring>#include<string& 阅读全文

posted @ 2012-03-28 18:09 More study needed. 阅读(205) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 7 8 9 10 ··· 19 下一页

导航

书山有径勤为路>>>>>>>>

<<<<<<<<学海无涯苦作舟!