摘要: #include<stdio.h>#include<string.h>#include<stdlib.h>struct tree{ int lev; struct tree*next[26];};tree root;char str[12];void creat_tree(char *str){ int i,j,len,id; len=strlen(str); tree *p=&root,*temp; for(i=0;i<len;i++){ id=str[i]-'a'; if(p->next[id]==NULL){ tem 阅读全文
posted @ 2012-08-03 13:19 xxx0624 阅读(294) 评论(0) 推荐(0) 编辑
摘要: 题目意译:有n个人围在桌子前面喝茶,等大家都坐定后,必然有个前后左右顺序,比如:a左边b,b左边c,依次类推,最后一个假设是g,那么他左边必然是a。形成一个圆环。现在有个规则,规定每次只能相邻两个人进行交换位置。请问要经过多少次交换,才能让之前位置交换(b左边a,c左边b,a左边是g)思路:大家都清楚假定是一排的情况下:a b c d e f g如果位置交换后:g f e d c b a需要经过n*(n-1)/2次交换(冒泡法进行交换)现在情况是环形,试问能不能将环拆分成两个线性,然后进行交换,再拼接在一起。举例如下:a b c d e f g(g后面又是a)如果分成a b c,d e f g 阅读全文
posted @ 2012-08-03 10:56 xxx0624 阅读(269) 评论(0) 推荐(0) 编辑