随笔分类 -  Algorithms

摘要:1.问题描述 旅行商问题(Travelling Salesman Problem, 简记TSP,亦称货郎担问题):设有n个城市和距离矩阵D=[dij],其中dij表示城市i到城市j的距离,i,j=1,2 … n,则问题是要找出遍访每个城市恰好一次的一条回路并使其路径长度为最短。 利用模拟退火算法(S 阅读全文
posted @ 2018-10-30 10:44 天涯惟笑 阅读(1886) 评论(0) 推荐(1)
摘要:1.问题描述 小孩分油问题 两个小孩去打油,一人带了一个一斤的空瓶,另一个带了一个七两、一个三两的空瓶。原计划各打一斤油,可是由于所带的钱不够,只好两人合打了一斤油,在回家的路上,两人想平分这一斤油,可是又没有其它工具。试仅用三个瓶子(一斤、七两、三两)精确地分出两个半斤油来。 2.算法设计 令状态 阅读全文
posted @ 2018-10-30 10:29 天涯惟笑 阅读(1559) 评论(0) 推荐(0)
摘要:一、题目 Description 周末,小 F 去参加画展,他希望在画展中能够欣赏到尽可能多的画作。 画展的场地是一个 n m 大小的长方形广场,对于其中的每一个格子,它可能是空地或 者是一个展板,如果当前格子为空地,则用’.’表示。如果为展板,则用‘ ’表示。对于任 意两个相邻的格子,如果一个为空 阅读全文
posted @ 2017-10-17 13:31 天涯惟笑 阅读(186) 评论(0) 推荐(0)
摘要:一、题目 Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) Push element x onto stack. pop() Remove 阅读全文
posted @ 2017-09-13 20:27 天涯惟笑 阅读(380) 评论(0) 推荐(0)
摘要:一、题目 Description Bessie is such a hard working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her next N 阅读全文
posted @ 2017-08-30 16:08 天涯惟笑 阅读(374) 评论(0) 推荐(0)
摘要:一、题目 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his fie 阅读全文
posted @ 2017-08-24 15:33 天涯惟笑 阅读(215) 评论(0) 推荐(0)
摘要:一、题目 Description Farmer John commanded his cows to search for different sets of numbers that sum to a given number. The cows use only numbers that are 阅读全文
posted @ 2017-08-20 15:25 天涯惟笑 阅读(247) 评论(0) 推荐(0)
摘要:一、题目 Description The cows don't use actual bowling balls when they go bowling. They each take a number (in the range 0..99), though, and line up in a 阅读全文
posted @ 2017-08-19 22:28 天涯惟笑 阅读(181) 评论(0) 推荐(0)
摘要:一、题目 Description Farmer John went to cut some wood and left N (2 ≤ N ≤ 100,000) cows eating the grass, as usual. When he returned, he found to his hor 阅读全文
posted @ 2017-08-10 20:31 天涯惟笑 阅读(365) 评论(0) 推荐(0)
摘要:一、题目 Description Our chemical biologists have invented a new very useful form of life called stripies (in fact, they were first called in Russian polo 阅读全文
posted @ 2017-08-09 22:38 天涯惟笑 阅读(251) 评论(0) 推荐(0)
摘要:一、题目 Description As a reward for record milk production, Farmer John has decided to start paying Bessie the cow a small weekly allowance. FJ has a set 阅读全文
posted @ 2017-08-08 17:01 天涯惟笑 阅读(1380) 评论(0) 推荐(0)
摘要:一、题目 Description A factory produces products packed in square packets of the same height h and of the sizes 1 1, 2 2, 3 3, 4 4, 5 5, 6 6. These produc 阅读全文
posted @ 2017-08-06 16:01 天涯惟笑 阅读(347) 评论(0) 推荐(0)
摘要:一、题目 Description The cows have purchased a yogurt factory that makes world famous Yucky Yogurt. Over the next N (1 include define MAX_N 10005 using na 阅读全文
posted @ 2017-08-06 13:38 天涯惟笑 阅读(829) 评论(0) 推荐(0)
摘要:一、题目 Description Oh those picky N (1 Stall 2 .. c2 c4 .. .. Stall 3 .. .. c3 .. .. .. .. Stall 4 .. .. .. c5 .. .. .. Other outputs using the same num 阅读全文
posted @ 2017-08-05 17:14 天涯惟笑 阅读(246) 评论(0) 推荐(0)
摘要:一、题目 Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point loc 阅读全文
posted @ 2017-08-04 14:51 天涯惟笑 阅读(271) 评论(0) 推荐(0)
摘要:一、算法说明 数据结构中经常需要用到各种排序算法,故参考网上代码,将九个排序算法整合在一起,以便日后使用。算法运行时,可以选择所要采用的排序算法,并会输出每一趟的排序过程,更利于对排序算法的理解。 二、运行截图 三、代码 include include include define MAX_SIZE 阅读全文
posted @ 2017-08-03 18:34 天涯惟笑 阅读(432) 评论(0) 推荐(0)
摘要:一、题目 Description Farmer John is assigning some of his N (1 include define MAX_N 25005 using namespace std; typedef pair P; int N, T; int cnt; P a[MAX_ 阅读全文
posted @ 2017-08-03 18:24 天涯惟笑 阅读(284) 评论(0) 推荐(0)
摘要:一、题目 Description The cows play the child's game of hopscotch in a non traditional way. Instead of a linear set of numbered boxes into which to hop, th 阅读全文
posted @ 2017-08-03 18:22 天涯惟笑 阅读(163) 评论(0) 推荐(0)
摘要:一、题目 Description FJ and his cows enjoy playing a mental game. They write down the numbers from 1 to N (1 include using namespace std; int N, sum; int 阅读全文
posted @ 2017-08-03 18:19 天涯惟笑 阅读(178) 评论(0) 推荐(0)
摘要:一、题目 Description Given a number of distinct decimal digits, you can form one integer by choosing a non empty subset of these digits and writing them i 阅读全文
posted @ 2017-08-03 18:16 天涯惟笑 阅读(190) 评论(0) 推荐(0)