随笔分类 - 笔试题练习
摘要:给定一个单词集合Dict,其中每个单词的长度都相同。现从此单词集合Dict中抽取两个单词A、B,我们希望通过若干次操作把单词A变成单词B,每次操作可以改变单词的一个字母,同时,新产生的单词必须是在给定的单词集合Dict中。求所有行得通步数最少的修改方法。 举个例子如下:Given: A = "hit...
阅读全文
摘要:current遍历,整个数组序列,current指1不动,current指0,与begin交换,而后current++,begin++,current指2,与end交换,而后,current不动,end--。http://blog.csdn.net/v_july_v/article/details/...
阅读全文
摘要:链表相交需要判断有无循环,无循环直接找最后一个节点进行比较,有循环找某个循环点然后看看另一条是否也有这个点。找循环链表入口比较牛逼:在p2和p1第一次相遇的时候,假定p1走了n步,环路的入口是在h步的时候经过的,那么有 p1走的路径: h+c = n; c为p1和p2相交点,距离环路入口的距离 p2...
阅读全文
摘要:阿里巴巴笔试的时候遇到了这个题,在网上找到了一篇好文,特地转发至此。http://sxnuwhui.blog.163.com/blog/static/137068373201242374810542/http://www.doc88.com/p-911955355117.html
阅读全文
摘要:经过这几轮笔试,发现智力题就那么10多20道,所以慢慢收集了一下。、分布转自:http://blog.csdn.net/randyjiawenjie/article/details/6752098http://www.cnrencai.com/maishishiti/19163.html感谢分享!有1000瓶药物,但是其中有一瓶是有毒的,小白鼠吃了一个星期以后就会死掉!请问,在一个星期内找出有毒的药物,最少需要多少只小白鼠?解答:用二进制的思路去思考,1000瓶药代表了1000种状态,那么1000用二进制表示可以用一个10位的二进制数就可以全部表示出来,考虑用十只白鼠来试验,用0和1代表它们最
阅读全文
摘要:#include #include xp(int num[], int n){ int min; int temp; int i; int j; for (i = 0; i num[j]){ min = j; } } temp = num[min]; num[min] = num[i]; num[i] = temp; }}main(){ int i; int num[] = {1, -2, 3, 10, -4, 7, 2, -5}; ...
阅读全文
摘要:拆分技术主要用于将一个链表分开,或者是按照一定的规律排列完再合并为一条链表。下面是最简单的一种a,b成对出现#include #include typedef struct Node{ int content; struct Node* next;}LNode;init(LNode** head){ *head = (LNode*)malloc(sizeof(LNode)); (*head)->content = 0; (*head)->next = NULL;}insert(LNode* head, int num){ LNode* newNode = (...
阅读全文
摘要:#include #include find(int num[], int n){ int max; int maxX; int i; int temp; int tempX; tempX = 0; temp = 1; max = 0; maxX = 0; for (i = 1; i max){ max = temp; maxX = tempX; } temp = 1; tempX = i; }...
阅读全文
摘要:#include #include int delX(int num[], int n, int x){ int i, j; i = 0; j = 0; for (i = 0; i < n; i++){ if (num[i] != x){ num[j] = num[i]; j++; } } return j;}print(int num[], int n){ int i; for (i = 0; i < n; i++){ printf("%d ", num[i]...
阅读全文
摘要:#include #include typedef struct Node{ int content; struct Node* next;}LNode;init(LNode** head){ *head = (LNode*)malloc(sizeof(LNode)); (*head)->content = 0; (*head)->next = NULL;}insert(LNode* head, int num){ LNode* newNode = (LNode*)malloc(sizeof(LNode)); newNode->content = nu...
阅读全文
摘要:题目说明: 假設有一個背包的負重最多可達8公斤,而希望在背包中裝入負重範圍內可得之總價物品,假設是水果好了,水果的編號、單價與重量如下所示: 0 李子 4KG NT$4500 1 蘋果 5KG NT$5700 2 橘子 2KG NT$2250 3 草莓 1KG NT$1100 4 甜瓜 6KG NT$6700 首先,是每种水果都只有一个的算法。#include #include int getMax(int fruitP[], int fruitW[], int form[][9], int fruitNum, int bagW){ int i, j; for(i = 1; i ...
阅读全文
摘要:特点是:子问题出现重叠;使用空间换取时间,因此一般需要一个表作为空间使用;用于最优化的处理,并且拥有最优子结构;无后效性;操作步骤:确定状态变量;确定决策以及状态转移方程;例子:http://blog.163.com/guixl_001/blog/static/41764104200863015855721/ http://www.cnblogs.com/yutoulck/p/3584375.html理解动态规划并不是很难,难的是自己从问题推断出需要应用动态规划并且懂得应用动态规划,状态变量以及状态转移方程的处理需要一定的思考。
阅读全文
摘要:#include #include int geZiQuShu(int num[][4], int h, int l){ int up, left; if(h left){ return up + num[h][l]; } else{ return left + num[h][l];; }}main(){ int num[4][4] = {20, 20, 20, 4, 5, 6, 20, 8, 9, 10, 20, 12, 13, 14, 20, 20}; int result; result = geZiQuShu...
阅读全文
摘要:#include #include int transform(char str[]){ int i = 0; int result = 0; while(str[i] != '\0'){ result = result * 10 + str[i] - '0'; i++; } return result;}main(){ char* str = "1234"; int result; result = transform(str); printf("%d \n", result);}
阅读全文
摘要:#include #include find(int num[][3], int h, int l, int x){ int i, j; int isFinded = 0; i = 0; j = l - 1; while(i = 0){ if(num[i][j] == x){ isFinded = 1; break; } else if(num[i][j] < x) i++; else j--; } if(isFinded == 1) printf("%...
阅读全文
摘要:#include #include JO(int num[], int n){ int i = 0; int j = n - 1; while(i < j){ for(; i < j; i++){ if(isO(num[i])) break; } for(; i < j; j--){ if(!isO(num[j])) break; } if(i < j){ swap(num, i, j); i++;j--; ...
阅读全文
摘要:#include #include int ttj(int n){ int n1; int n2; if(n == 1) return 1; if(n == 2) return 2; n1 = ttj(n - 1); n2 = ttj(n - 2); return n2 + n1;}main(){ int num; num = ttj(3); printf("%d",num);}
阅读全文
摘要:#include #include swap(char* str, int b, int e){ char temp = str[b]; str[b] = str[e]; str[e] = temp;}print(char* str, int n){ int i; for(i = 0; i< n; i++){ printf("%c ", str[i]); } printf("\n");}int quanXuLie(char* str, int b, int n){ int i; if(n <= 1){ print...
阅读全文
摘要:#include #include typedef struct Node{ int content; struct Node* next;}LNode;init(LNode** head){ *head = (LNode*)malloc(sizeof(LNode)); (*head)->content = 0; (*head)->next = NULL;}insert(LNode* head, int num){ LNode* newNode = (LNode*)malloc(sizeof(LNode)); newNode -> content = ...
阅读全文
摘要:#include find(char* str, int n){ int i = 1; char temp = str[0]; int num = 1; while(i < n){ if(str[i] == temp){ num++; } else if(num == 0){ temp = str[i]; num = 0; } else{ num--; } i++; } pr...
阅读全文

浙公网安备 33010602011771号