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

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

09 2011 档案

Hash和枚举 解决POJ 1840
摘要:DescriptionConsider equations having the following form:a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0The coefficients are given integers from the interval [-50,50].It is consider a solution a system (x1, x2, x3, x4, x5) that verifies the equation, xi∈[-50,50], xi != 0, any i∈{1,2,3,4,5}.Determine how many sol 阅读全文

posted @ 2011-09-26 19:21 More study needed. 阅读(245) 评论(0) 推荐(1) 编辑

Huffman和Priority_queue 解决POJ 1521
摘要:题目:http://poj.org/problem?id=1521题目大意:给定字符串,求哈夫曼编码长和它与等长编码的比值做这道题目的时候wrang了好几次,但是,经过调试之后,我彻底了解了哈夫曼树的过程说来相当有价值了。在下面我也会分享出来的。View Code #include <iostream> #include "cstdio"#include "string"#include "cstring"#include <queue> using namespace std; struct Num{ int 阅读全文

posted @ 2011-09-25 22:06 More study needed. 阅读(314) 评论(0) 推荐(0) 编辑

Huffman和Priority_queue 解决POJ 3253
摘要:DescriptionFarmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needsN(1 ≤N≤ 20,000) planks of wood, each having some integer lengthLi(1 ≤Li≤ 50,000) units. He then purchases a single long board just long enough to saw into theNplanks (i 阅读全文

posted @ 2011-09-25 11:41 More study needed. 阅读(222) 评论(0) 推荐(0) 编辑

Huffman算法总结归纳
摘要:基本术语 哈夫曼树又称为最优树. 1、路径和路径长度 在一棵树中,从一个结点往下可以达到的孩子或子孙结点之间的通路,称为路径。 通路中分支的数目称为路径长度。若规定根结点的层数为1, 则从根结点到第L层结点的路径长度为L-1。 2、结点的权及带权路径长度 若将树中结点赋给一个有着某种含义的数值,则这个数值称为该结点的权。 结点的带权路径长度为:从根结点到该结点之间的路径长度与该结点的权的乘积。 3、树的带权路径长度 树的带权路径长度规定为所有叶子结点的带权路径长度之和,记为WPL。Huffman的构造方法 假设有n个权值,则构造出的哈夫曼树有n个叶子结点。 n个权值分... 阅读全文

posted @ 2011-09-25 10:56 More study needed. 阅读(436) 评论(0) 推荐(0) 编辑

Hash算法——暴雪
摘要:暴雪公司有个经典的字符串的hash公式先提一个简单的问题,假如有一个庞大的字符串数组,然后给你一个单独的字符串,让你从这个数组中查找是否有这个字符串并找到它,你会怎么做?有一个方法最简单,老老实实从头查到尾,一个一个比较,直到找到为止,我想只要学过程序设计的人都能把这样一个程序作出来,但要是有程序员把这样的程序交给用户,我只能用无语来评价,或许它真的能工作,但也只能如此了。最合适的算法自然是使用HashTable(哈希表),先介绍介绍其中的基本知识,所谓Hash,一般是一个整数,通过某种算法,可以把一个字符串"压缩"成一个整数,这个数称为Hash,当然,无论如何,一个32位 阅读全文

posted @ 2011-09-25 10:30 More study needed. 阅读(526) 评论(0) 推荐(0) 编辑

Hash技术的总结归纳
摘要:在看哈希之前还是来看看“散列函数(哈希函数)”吧,后面会用到的。解决冲突的方法。 开放定址法。如果h(k)已经被占用,按如下序列探查: (h(k)+p(1))%TSize, (h(k)+p(2))%TSize, …,(h(k)+p(i))%TSize,… 其中,h(k)为哈希函数,TSize为哈希表长,p(i)为探查函数。 在 h(k)+p(i-1))%TSize的基础上,若发现冲突, 则使用增量 p(i) 进行新的探测,直至无冲突出现为止。 其中,根据探查函数p(i)的不同,开放定址法又分为 (1)线性探查法(p(i) = i : 1 , 2 , 3 , …), ... 阅读全文

posted @ 2011-09-24 10:57 More study needed. 阅读(1823) 评论(0) 推荐(0) 编辑

STL之map——解决POJ 2503
摘要:DescriptionYou have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.InputInput consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message 阅读全文

posted @ 2011-09-23 22:52 More study needed. 阅读(179) 评论(0) 推荐(0) 编辑

STL之stack——解决POJ 1028
摘要:DescributionStandard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reached by moving backward and forward. In this problem, you are asked to implement this. 阅读全文

posted @ 2011-09-23 22:45 More study needed. 阅读(214) 评论(0) 推荐(0) 编辑

BFS解决POJ 2243
摘要:DescriptionYou are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid 阅读全文

posted @ 2011-09-23 22:40 More study needed. 阅读(209) 评论(0) 推荐(0) 编辑

DFS解决POJ 1979
摘要:DescriptionThere is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles. Write a program to count the nu 阅读全文

posted @ 2011-09-23 22:38 More study needed. 阅读(146) 评论(0) 推荐(0) 编辑

BFS解决POJ 2386
摘要: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 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Farmer John would like to figure 阅读全文

posted @ 2011-09-23 22:37 More study needed. 阅读(200) 评论(0) 推荐(0) 编辑

DFS解决POJ 2386
摘要: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 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Farmer John would like to figure 阅读全文

posted @ 2011-09-23 22:35 More study needed. 阅读(151) 评论(0) 推荐(0) 编辑

BFS解决POJ 2251
摘要:DescriptionYou are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid 阅读全文

posted @ 2011-09-23 22:34 More study needed. 阅读(182) 评论(0) 推荐(0) 编辑

动态规划解决POJ 3624
摘要:DescriptionBessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weightWi (1 ≤ Wi ≤ 400), a 'desirability' factor Di ( 阅读全文

posted @ 2011-09-23 22:23 More study needed. 阅读(223) 评论(0) 推荐(0) 编辑

一道简单但是经典的动态规划题
摘要:描述 打败万恶的ghost以后,将军准备回寝室告诉大伙儿这个消息,没想到杯具又发生了… 你知道有种鬼叫路鬼吗?让人莫名其妙的迷路,将军就被这种鬼上身了。将军本来要上楼梯的,但是因为鬼上身,他要不就上一层楼,要不就下一层楼,这个是随机的,他不能控制自己啦! 假设将军住在第M楼,因为体力原因,将军只能上或者下N次楼,刚开始将军在K楼,假设东6宿舍共有100层。现在问当体力消耗完的时候,将军刚好回到寝室那一层有多少种可能。 例如:将军住在5楼,将军的能上/下5次楼,现在在1楼, 那么将军将回不到寝室啦,为什么?我也不知道。 输入有多组测试数据,每组测试数据共一行,为M,N,K(0 < N &l 阅读全文

posted @ 2011-09-23 22:22 More study needed. 阅读(288) 评论(0) 推荐(0) 编辑

Kruskal算法解决POJ 1861
摘要:题目:http://poj.org/problem?id=1861说下题意,给出节点个数m和边数n,下面n行给出边(x,y)以及权值w。输出第一行为最小生成树中的最大边权值,第二行为一个可行生成树方案的边数k,下面k行为可行生成树的k条边。题目是Special Judge,意思就是不具有唯一解,可能有多解,样例输出为以下结果也可算对。131 32 42 3一样按照Kruskal解题即可,结果虽然不唯一,但是最小生成树一定是可行解之一。将边加入生成树时记录最大权值和边信息然后输出即可。View Code #include "iostream"#include "al 阅读全文

posted @ 2011-09-23 22:17 More study needed. 阅读(281) 评论(0) 推荐(0) 编辑

CSS设置字体——声声明多属性
摘要:1 <html> 2 <head> 3 <style type="text/css"> 4 p.ex1 5 { 6 font:italic arial,sans-serif; 7 } 8 9 p.ex210 {11 font:italic bold 12px/30px arial,sans-serif;12 }13 </style>14 </head>15 16 <body>17 <p class="ex1">18 This is a paragraph. This is 阅读全文

posted @ 2011-09-23 20:57 More study needed. 阅读(279) 评论(0) 推荐(0) 编辑

Kruskal算法解决POJ 1258
摘要:DescriptionFarmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course.Farmer John ordered a high speed connection for his farm and is going to share his connectivity with the other farmers. T 阅读全文

posted @ 2011-09-23 20:55 More study needed. 阅读(309) 评论(0) 推荐(0) 编辑

Kruskal算法解决POJ 2421--有点难度
摘要:DescriptionThere are N villages, which are numbered from 1 to N, and you should build some roads such that every two villages can connect to each other. We say two village A and B are connected, if and only if there is a road between A and B, or there exists a village C such that there is a road bet 阅读全文

posted @ 2011-09-22 19:10 More study needed. 阅读(476) 评论(0) 推荐(0) 编辑

Kruskal和map映射 解决POJ 2075
摘要:DescriptionYou are the owner of SmallCableCo and have purchased the franchise rights for a small town. Unfortunately, you lack enough funds to start your business properly and are relying on parts you have found in an old warehouse you bought. Among your finds is a single spool of cable and a lot of 阅读全文

posted @ 2011-09-21 11:10 More study needed. 阅读(241) 评论(0) 推荐(0) 编辑

Kruskal算法解决POJ 1251
摘要:DescriptionThe Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensive to maintain. The Council of Elders must choose t 阅读全文

posted @ 2011-09-21 09:25 More study needed. 阅读(308) 评论(0) 推荐(2) 编辑

映射在编程中的应用
摘要:1.题目:判断断一个由a-z这26个字符组成的字符串中哪个字符出现的次数最多。#include<stdio.h>#include "string.h"int main(){ int n, Case[26], j, max; char str[1001]; scanf("%d", &n); for(int i=0; i<n; i++) { scanf("%s", str); memset(Case, 0, sizeof(Case)); for(j=0; j<strlen(str); j++) Case[s 阅读全文

posted @ 2011-09-19 22:23 More study needed. 阅读(559) 评论(0) 推荐(0) 编辑

CSS设置字体——异体和粗细
摘要:<1>.异体font-variant属性可以设定小型大写字母。小型大写字母不是一般的大写字母,也不是小写字母,这种字母采用不同大小的大写字母。 1 <html> 2 <head> 3 <style type="text/css"> 4 p.normal {font-variant:normal} 5 p.small {font-variant: small-caps} 6 </style> 7 </head> 8 9 <body>10 <p class="normal&quo 阅读全文

posted @ 2011-09-18 21:06 More study needed. 阅读(7557) 评论(0) 推荐(0) 编辑

CSS设置字体——系列和风格
摘要:首先来了解一下CSS字体:通用字体系列前面讨论过,实际上相同的字体可能有很多不同的称呼,不过 CSS 迈出了勇敢的一步,力图帮助用户代理把这种混乱状况理清楚。我们所认为的“字体”可能有许多字体变形组成,分别用来描述粗体、斜体文本,等等。例如,你可能已经对字体 Times 很熟悉。不过,Times 实际上是多种变形的一个组合,包括 TimesRegular、TimesBold、TimesItalic、TimesOblique、TimesBoldItalic、TimesBoldOblique,等等。Times 的每种变形都是一个具体的字体风格(font face),而我们通常认为的 Times 是 阅读全文

posted @ 2011-09-18 20:08 More study needed. 阅读(3878) 评论(0) 推荐(0) 编辑

CSS设置文本——字母、单词、段落
摘要:<1>字母大小写 1 <html> 2 <head> 3 <style type="text/css"> 4 h1 {text-transform: uppercase} 5 p.uppercase {text-transform: uppercase} 6 p.lowercase {text-transform: lowercase} 7 p.capitalize {text-transform: capitalize} 8 </style> 9 </head>10 11 <body>12 阅读全文

posted @ 2011-09-17 22:36 More study needed. 阅读(337) 评论(0) 推荐(0) 编辑

CSS设置文本——对齐、修饰、缩进
摘要:<1>.对齐文本 1 <html> 2 <head> 3 <style type="text/css"> 4 h1 {text-align: center} 5 h2 {text-align: left} 6 h3 {text-align: right} 7 </style> 8 </head> 9 10 <body>11 <h1>这是标题 1</h1>12 <h2>这是标题 2</h2>13 <h3>这是标题 3</h3&g 阅读全文

posted @ 2011-09-17 21:21 More study needed. 阅读(1879) 评论(0) 推荐(0) 编辑

CSS设置文本——行间距
摘要:<1>.用比例设置行间距 1 <html> 2 <head> 3 <style type="text/css"> 4 p.small {line-height: 90%} 5 p.big {line-height: 200%} 6 </style> 7 </head> 8 9 <body>10 <p>11 这是拥有标准行高的段落。12 在大多数浏览器中默认行高大约是 110% 到 120%。13 这是拥有标准行高的段落。14 这是拥有标准行高的段落。15 这... 阅读全文

posted @ 2011-09-17 17:12 More study needed. 阅读(17174) 评论(0) 推荐(0) 编辑

CSS设置文本——各个字符间距
摘要:CSS设置文本字符间的距离 1 <html> 2 <head> 3 <style type="text/css"> 4 h1 {letter-spacing: -0.5em} 5 h4 {letter-spacing: 20px} 6 </style> 7 </head> 8 9 <body>10 <h1>This is header 1</h1>11 <h4>This is header 4</h4>12 </body>13 </htm 阅读全文

posted @ 2011-09-17 16:47 More study needed. 阅读(412) 评论(0) 推荐(0) 编辑

CSS设置文本——颜色和大小
摘要:<1>.设置文本颜色 1 <html> 2 <head> 3 <style type="text/css"> 4 body {color: red} 5 h1 {color: #00ff00} 6 p.ex {color: rgb(0,0,255)} 7 </style> 8 </head> 9 10 <body>11 <h1>这是 heading 1</h1>12 <p>这是一段普通的段落。请注意,该段落的文本是红色的。在 body 选择器中定义了本页面 阅读全文

posted @ 2011-09-17 16:43 More study needed. 阅读(625) 评论(0) 推荐(0) 编辑

CSS设置背景——图片背景
摘要:<1>.默认设置下的背景图片 1 <html> 2 <head> 3 <style type="text/css"> 4 body {background-image: url(这个地方要写的就是你的图片的url地址了);} 5 </style> 6 </head> 7 8 <body> 9 </body>10 </html>那个url地址的填写该如何去做呢?比如你在E盘中新建了一个文件夹My Web,当然你的站点就是建在这里了。而在My Web中你又新建了一个文件夹 阅读全文

posted @ 2011-09-16 20:49 More study needed. 阅读(61480) 评论(0) 推荐(1) 编辑

Kruskal算法整理——求最小生成树
摘要:克鲁斯卡尔算法(Kruskal's algorithm)是两个经典的最小生成树算法的较为简单理解的一个。 这里面充分体现了贪心算法的精髓。 大致的流程可以用一个图来表示。这里的图的选择借用了Wikipedia上的那个。非常清晰且直观。 首先第一步,我们有一张图,有若干点和边 如下图所示: . . . . . . 第一步我们要做的事情就是将所有的边的长度排序,用排序的结果作为我们选择边的依据。 这里再次体现了贪心算法的思想。资源排序,对局部最优的资源进行选择。 排序完成后,我们率先选择了边AD。 这样我们的图就变成了 . . . . . . 第二步,在... 阅读全文

posted @ 2011-09-14 09:32 More study needed. 阅读(386) 评论(0) 推荐(0) 编辑

Prim算法的整理——求最小生成树
摘要:用Prim算法来求出最小生成树的过程Prim算法的描述:设图G =(V,E),其生成树的顶点集合为U。 ①、把v0放入U。 ②、在所有u∈U,v∈V-U的边(u,v)∈E中找一条最小权值的边,加入生成树。 ③、把②找到的边的v加入U集合。如果U集合已有n个元素,则结束,否则继续执行②。 其算法的时间复杂度为O(|E|*log|V|) 第2条是什么意思呢? 它的意思是从剩下的所有的边中找出最小的边,但是这个边是有要求的,也就是必须是与刚刚加入的顶点相通的权值最小的边。 如果还是不懂的话,就看看上面的图吧! 阅读全文

posted @ 2011-09-14 09:21 More study needed. 阅读(274) 评论(0) 推荐(0) 编辑

CSS设置背景——颜色背景
摘要:<1>.设置body的背景颜色 1 <html> 2 <head> 3 <style type="text/css"> 4 body {background-color: yellow} 5 h1 {background-color: #00ff00} 6 h2 {background-color: transparent} 7 p {background-color: rgb(250,0,255)} 8 p.no2 {background-color: gray; padding: 20px;} 9 ... 阅读全文

posted @ 2011-09-13 21:51 More study needed. 阅读(504) 评论(0) 推荐(0) 编辑

更深层次的DFS 解决POJ 2362
摘要: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 <= M <= 20, the number of sticks. M integers follow; each gives the length of 阅读全文

posted @ 2011-09-07 08:35 More study needed. 阅读(244) 评论(0) 推荐(0) 编辑

qsort的用法总结
摘要:1.自定义数字从大到小的排序函数 int cmp(const void *a, const void *b) //qsort的自定义函数 { return *(int *)b - *(int *)a; } qsort(arry, N, sizeof(arry[0]), cmp); //qsort的具体调用 (1).qsort函数的具体调用形式如下: qsort(开始比较的数组地址,比较的宽度,数组的类型,比较的函数) 注意:qsort不支持3个参数,更别说两个了,四个参数一个也不能少 为何将“开始比较的数组地址”和“比较的宽度”强调?且看下面。 (2).q... 阅读全文

posted @ 2011-09-05 08:51 More study needed. 阅读(228) 评论(0) 推荐(0) 编辑

记忆化搜索解决POJ 1088
摘要:DescriptionMichael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子中,一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上,这是最长... 阅读全文

posted @ 2011-09-05 08:01 More study needed. 阅读(1606) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

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

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

点击右上角即可分享
微信分享提示