Const_Lin
你从远方来, 我到远方去, 遥远的路程经过这里, 天空一无所有, 为何给我安慰。
摘要: 阅读全文
posted @ 2014-03-31 13:15 Const_Lin 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 堆排序与快速排序,归并排序一样都是时间复杂度为O(N*logN)的几种常见排序方法。学习堆排序前,先讲解下什么是数据结构中的二叉堆。二叉堆的定义二叉堆是完全二叉树或者是近似完全二叉树。二叉堆满足二个特性:1.父结点的键值总是大于或等于(小于或等于)任何一个子节点的键值。2.每个结点的左子树和右子树都是一个二叉堆(都是最大堆或最小堆)。当父结点的键值总是大于或等于任何一个子节点的键值时为最大堆。当父结点的键值总是小于或等于任何一个子节点的键值时为最小堆。下图展示一个最小堆:由于其它几种堆(二项式堆,斐波纳契堆等)用的较少,一般将二叉堆就简称为堆。堆的存储一般都用数组来表示堆,i结点的父结点下标就 阅读全文
posted @ 2014-03-15 15:41 Const_Lin 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 题目描述:如下数列,前5项分别是1/1,1/2,2/1,3/1,2/2……。输入n,输出第n项。1/1 1/2 1/3 1/4 1/52/1 2/2 2/3 2/43/1 3/2 3/34/1 4/25/1样例输入314712345样例输出2/12/41/459/99代码如下:#includeint main(){ int n; while(scanf("%d",&n) == 1) { int k = 1,s = 0; for(;;) { s += k;//s = 0 + ... 阅读全文
posted @ 2013-12-30 12:26 Const_Lin 阅读(366) 评论(0) 推荐(0) 编辑
摘要: 题目描述:DescriptionGeorge took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were originally. Please help him and design a program which 阅读全文
posted @ 2013-12-10 22:09 Const_Lin 阅读(248) 评论(0) 推荐(0) 编辑
摘要: 题目描述:Problem DescriptionGiven a set of sticks of various lengths, is it possible to join them end-to-end to form a square?InputThe first line of input contains N, the number of test cases. Each test case begins with an integer 4 7 #include 8 9 int visit[20];10 bool flag;11 int number[20];12 int n,.. 阅读全文
posted @ 2013-11-30 22:28 Const_Lin 阅读(277) 评论(0) 推荐(0) 编辑
摘要: 题目描述:Problem DescriptionSuppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.A blockhouse is a small castle that has four openings through which to shoot. The four openings are facing Nort 阅读全文
posted @ 2013-11-25 20:50 Const_Lin 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 题目描述:DescriptionDue to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 2 char map[100][100]; 3 int n,m; 4 void dfs(int i,int j); 5 int main() 6 { 7 using namespace std; 8 //int n,m; 9 int sum = 0;10 cin >> n >>. 阅读全文
posted @ 2013-11-18 21:32 Const_Lin 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 题目描述:DescriptionAn army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it immediatelly falls off it. When two ants meet they turn back and start walking in opposite directions. We know the original positions of a 阅读全文
posted @ 2013-11-11 22:08 Const_Lin 阅读(223) 评论(0) 推荐(0) 编辑
摘要: 题目描述:InputThe first line of the input contains an integer T(1 2 #include 3 using namespace std; 4 string ans; 5 void bintadd(string a,string b) 6 { 7 int alen = a.length() - 1,blen = b.length() - 1;//alen,blen分别存放a,b字符串的最大下标 8 int up = 0,i = 0,j,te;//up存放进位值,te存放余数 9 10 while(alen >= 0 |... 阅读全文
posted @ 2013-11-07 22:29 Const_Lin 阅读(284) 评论(0) 推荐(0) 编辑
摘要: 题目描述:/**Generate mask indicating leftmost 1 in x. Assume w=32.*For example 0xFF00 -> 0x8000, and 0x6600 -> 0x4000.* If x = 0, then return 0.*/代码如下: 1 #include 2 int leftmost_one(unsigned x); 3 int main() 4 { 5 printf("Please enter number: "); 6 unsigned x; 7 scanf("%x",& 阅读全文
posted @ 2013-11-05 14:31 Const_Lin 阅读(695) 评论(4) 推荐(0) 编辑