摘要: Write code to remove duplicates from an unsorted linked list FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed?如果我们用缓冲区,我们可以在hash表里跟踪每一个元素,同时删除任何重复的。本文主要是记载线性表的一些实现方法。struct LNode { ElemType data; struct LNode *next; }; typedef struct LNode *Linklist;线性表的定义;void CreatL.. 阅读全文
posted @ 2012-07-18 20:43 JWMNEU 阅读(166) 评论(0) 推荐(0) 编辑
摘要: Write an algorithm such that if an element in an MxN matrix is 0, its entire row andcolumn is set to 0写一个算法使得把一个M*N的矩阵中0元素所在位置的行列设置为零At first glance, this problem seems easy: just iterate through the matrix and every time wesee a 0, set that row and column to 0 There’s one problem with that soluti.. 阅读全文
posted @ 2012-07-14 21:02 JWMNEU 阅读(225) 评论(0) 推荐(0) 编辑
摘要: Given an image represented by an NxN matrix, where each pixel in the imageis 4bytes, write a method to rotate the image by 90 degrees Can you do this in place?描述:给定一个N*N的图像,每个位置的像素是4byte,写一个方法用来在原来的空间内旋转图像90度。思路:我们可以按层来旋转。void matrixRotation(int [][]a,int n) { for(int layer=0;layer<n;layer++) { . 阅读全文
posted @ 2012-07-14 19:57 JWMNEU 阅读(325) 评论(0) 推荐(0) 编辑
摘要: DescriptionA palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inserted into the string in order to obtain a palindrome.As an exa 阅读全文
posted @ 2012-04-11 18:36 JWMNEU 阅读(137) 评论(0) 推荐(0) 编辑
摘要: DescriptionA cyclic number is an integer n digits in length which, when multiplied by any integer from 1 to n, yields a"cycle"of the digits of the original number. That is, if you consider the number after the last digit to "wrap around"back to the first digit, the sequence of di 阅读全文
posted @ 2012-04-11 15:43 JWMNEU 阅读(230) 评论(0) 推荐(0) 编辑
摘要: 骑士旅游(Knight tour)在十八世纪初倍受数学家与拼图迷的注意,它什么时候被提出已不可考,骑士的走法为西洋棋的走法,骑士可以由任一个位置出发,它要如何走完所有的位置? 骑士的走法,基本上可以使用递归来解决,但是纯綷的递归在维度大时相当没有效率,一个聪明的解法由J.C. Warnsdorff在1823年提出,简单的说,先将最难的位置走完,接下来的路就宽广了,骑士所要走的下一步,「为下一步再选择时,所能走的步数最少的一步。」,使用这个方法,在不使用递归的情况下,可以有较高的机率找出走法(找不到走法的机会也是有的)。 在一个n m 格子的棋盘上,有一只国际象棋的骑士在棋盘的左下角,骑士只.. 阅读全文
posted @ 2012-02-28 23:19 JWMNEU 阅读(186) 评论(0) 推荐(0) 编辑
摘要: 河内之塔(TowersofHanoi)是法国人M.Claus(Lucas)于1883年从泰国带至法国的,河内为越战时北越的首都,即现在的胡志明市;1883年法国数学家EdouardLucas曾提及这个故事,据说创世纪时Benares有一座波罗教塔,是由三支钻石棒(Pag)所支撑,开始时神在第一根棒上放置64个由上至下依由小至大排列的金盘(Disc),并命令僧侣将所有的金盘从第一根石棒移至第三根石棒,且搬运过程中遵守大盘子在小盘子之下的原则,若每日仅搬一个盘子,则当盘子全数搬运完毕之时,此塔将毁损,而也就是世界末日来临之时。解法如果柱子标为ABC,要由A搬至C,在只有一个盘子时,就将它直接搬至C 阅读全文
posted @ 2012-01-09 23:12 JWMNEU 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 感觉自己用C++越来越生疏了,所以在网上找到了一些题,然后每天做一个练习,不为什么,从基础做起,权当作自己练习的见证了,今天就从最简单的冒泡排序开始~~问题描述:问题的提出:某大学开田径运动会,现有12名选手参加100米比赛,对应的运动员号及成绩如表所示,请按照成绩排名并输出,要求每一行输出名次、运动员号及成绩。要求用冒泡法排序。运动员号成绩(秒)运动员号成绩(秒)00113.603114.900214.803612.601012.003713.401112.710212.502315.632515.302513.443812.7#include <iostream> #inclu 阅读全文
posted @ 2012-01-06 23:04 JWMNEU 阅读(531) 评论(0) 推荐(0) 编辑