锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久天天躁狠狠躁夜夜avapp ,久久人妻少妇嫩草AV无码专区,久久免费视频网站http://www.shnenglu.com/Joe/archive/2011/07/19/151405.htmlsimplyzhaosimplyzhaoTue, 19 Jul 2011 11:57:00 GMThttp://www.shnenglu.com/Joe/archive/2011/07/19/151405.htmlhttp://www.shnenglu.com/Joe/comments/151405.htmlhttp://www.shnenglu.com/Joe/archive/2011/07/19/151405.html#Feedback0http://www.shnenglu.com/Joe/comments/commentRss/151405.htmlhttp://www.shnenglu.com/Joe/services/trackbacks/151405.html闂:

Given a random number generator which can generate the number in range (1,5) uniformly. How can you use it to build a random number generator which can generate the number in range (1,7) uniformly?


(緇欏畾涓涓殢鏈烘暟鐢熸垚鍣紝榪欎釜鐢熸垚鍣ㄨ兘鍧囧寑鐢熸垚1鍒?(1,5)鐨勯殢鏈烘暟錛屽浣曚嬌鐢ㄨ繖涓敓鎴愬櫒鐢熸垚鍧囧寑鍒嗗竷鐨?鍒?(1,7)鐨勬暟?)

瑙f硶涓:
鎷掔粷閲囨牱瀹氱悊
綆鍗曠殑璇? 鎶?1-5 鐨勯殢鏈烘暟鍙戠敓鍣ㄧ敤涓ゆ, 鎷兼垚涓涓?榪涘埗鐨勬暟, 灝辨槸1-25. 灝嗚繖 1-25 騫沖潎鍒嗛厤鐨?5縐嶆儏鍐墊槧灝勫埌7縐嶆儏鍐典笂, 闂灝辮В鍐充簡. 鍥犱負21鏄?鐨勫嶆暟, 鎴戜滑鍙互姣忎笁涓槧灝勫埌涓涓? 鍗?-3 鏄犲皠鍒?, …, 19-21 鏄犲皠鍒?. 鍙, 榪欎簺鎯呭喌涔嬮棿鐨勬鐜囨槸涓鏍風殑. 閭d箞, 瑕佹槸鎷兼垚鐨勬暟瀛楁濂芥槸 22-25 榪欏洓涓憿? 鏈変袱縐嶆柟娉? 絎竴縐嶆槸涓㈠純榪欎釜鏁板瓧, 浠庡ご鍐嶆潵, 鐩村埌鎷兼垚鐨勬暟瀛楀湪1-21涔嬮棿. 鍥犱負榪欎釜鏄釜姒傜巼綆楁硶, 涓嶈兘淇濊瘉姣忔閮借兘钀藉湪1-21, 鎵浠ラ噰鏍風殑瀵嗗害涓嶉珮. 榪樻湁涓縐嶆柟娉? 鏄, 鍋囧钀藉埌浜?22-25, 閭h繖嬈$殑閲囨牱緇撴灉灝辯敤涓婃鐨? 鍙互璇佹槑, 榪欑湅涓婂幓涓や釜浜掔浉鐭涚浘鐨勭畻娉? 緇撴灉閮借兘鍧囩瓑鐨勫緱鍒扮瓑姒傜巼鐨勫垎甯? (鍓嶈呭彨鍋?Reject Sampling, 鍚庤呭彨鍋?Metropolis Algorithm, 閮芥槸鏁板鐗╃悊妯℃嫙閲岄潰甯哥敤鐨勬柟娉?

瑙f硶浜?
浜岃繘鍒?br />1-2鏄犲皠鍒?錛?璺寵繃錛?-5鏄犲皠鍒?
鐢熸垚涓変綅鐨勪簩榪涘埗鍗沖彲


simplyzhao 2011-07-19 19:57 鍙戣〃璇勮
]]>
浠巒涓猧tems涓殢鏈洪夋嫨m涓殑闂http://www.shnenglu.com/Joe/archive/2011/07/18/151277.htmlsimplyzhaosimplyzhaoMon, 18 Jul 2011 01:32:00 GMThttp://www.shnenglu.com/Joe/archive/2011/07/18/151277.htmlhttp://www.shnenglu.com/Joe/comments/151277.htmlhttp://www.shnenglu.com/Joe/archive/2011/07/18/151277.html#Feedback0http://www.shnenglu.com/Joe/comments/commentRss/151277.htmlhttp://www.shnenglu.com/Joe/services/trackbacks/151277.html闂鏉ユ簮: 緙栫▼鐝犵帒

瑙f硶涓:
閬嶅巻榪檔涓猧tems錛屽閥濡欏湴鍒╃敤姒傜巼鏉ョ瓫閫?
void
generate_random_m_from_n(
int n, int m)
{
    
int i, remaining, select = m;
    srand(time(NULL));
    
for(i=0; i<n; i++) {
        remaining 
= n - i;
        
if(rand()%remaining < select) {
            printf(
"%d\t", i);
            
--select;
        }
    }
    printf(
"\n");
}

瑙f硶浜?
shuffle錛屽嵆闅忔満媧楃墝紼嬪簭錛岀劧鍚庨夋嫨鍓峬涓猧tems鍗沖彲
浠g爜鍙傝? http://blog.fuqcool.com/2011/04/17/algorithm-shuffle.html

媧楃墝綆楁硶鐨勪竴縐嶅疄鐜?/a>

浣滆咃細fuqcool 鍙戝竷鏃墮棿錛?011-04-17 23:16:02 鍒嗙被錛?algorithms

鏈榪戣嚜宸卞湪鍋氫竴涓皬鐨勭▼搴忥紝闇瑕佹妸涓涓泦鍚堥噷闈㈢殑鍏冪礌鍏ㄩ儴闅忔満鍦版墦鏁c傝嚜宸辨兂浜嗕竴涓柟娉曪紝澶嶆潅搴︽槸n錛岃寰椾笉澶揩銆傚悗鏉ュ弬鐓т簡涓涓媝ython鍏充簬shuffle鐨勭畻娉曪紝鍙戠幇鎴戠殑鏂規硶璺熷畠鐨勬槸涓鏍風殑錛岃繛python鐨勪唬鐮侀兘榪欎箞鍐欙紝鍙兘宸茬粡娌℃湁鍔炴硶鍐嶅揩浜嗗惂錛?/p>

涓嬮潰灝辨潵浠嬬粛媧楃墝綆楁硶錛岀敤C璇█鎻忚堪銆?/p>

綆楁硶鐨勫墠鎻愭槸鏈変竴涓駭鐢熼殢鏈烘暟鐨勫嚱鏁?/p>

// Generates a random integer between beg and end.
int GetRandomNumber(int beg, int end);

榪樻湁涓涓氦鎹㈠嚱鏁般?/p>

// Swap a and b.
void Swap(int a, int b);

涓婇潰涓や釜鍑芥暟鎴戝氨涓嶅啓鍑哄疄鐜頒簡錛屽洜涓鴻繖綃囨枃绔犵殑閲嶇偣鍦ㄤ簬綆楁硶鐨勮璁恒?/p>

鍋囪鎴戜滑鏈変竴鍫嗘墤鍏嬬墝錛屾庝箞鎵嶈兘鎶婅繖鍓墝瀹屽叏鎵撲貢鍛紵璁$畻鏈哄綋鐒朵笉鑳藉儚浜烘墜閭f牱媧楃墝銆備絾鏄畠鍙互浜х敓闅忔満鏁幫紝闅忔満鍦頒粠涓鍓墝涓娊鍑轟竴寮犵墝鏄彲浠ョ殑銆傛棦鐒惰繖鏍烽偅灝卞ソ鍔炰簡錛屾垜浠笉鍋滃湴浠庣墝鍫嗕腑闅忔満鎶藉彇涓寮犳墤鍏嬬墝錛岀劧鍚庢妸榪欎簺鐗屽爢璧鋒潵錛岀洿鍒板師鏉ョ殑鐗屽爢鍙墿涓嬩竴寮犵墝鐨勬椂鍊欎負姝€傝繖鏍蜂笉灝卞畬鎴愪簡媧楃墝鐨勫姩浣滀簡鍚椼?/p>

涓嬮潰鏄疌浠g爜錛?/p>

int Shuffle(int[] a, int len)
{
    for (int i = len - 1; i > 0; i--)
    {
        // Select an element from index 0 to i randomly;
        int index = GetRandomNumber(0, i);
        // exchange a[i] with a[index]
        Swap(a[index], a[i]);
    }
}

欏轟究涔熻創鍑簆ython鐨剅andom鍗曞厓鍏充簬shuffle鐨勫疄鐜幫細

def shuffle(self, x, random=None, int=int):
    """x, random=random.random -> shuffle list x in place; return None.

    Optional arg random is a 0-argument function returning a random
    float in [0.0, 1.0); by default, the standard random.random.
    """

    if random is None:
        random = self.random
    for i in reversed(xrange(1, len(x))):
        # pick an element in x[:i+1] with which to exchange x[i]
        j = int(random() * (i+1))
        x[i], x[j] = x[j], x[i]



simplyzhao 2011-07-18 09:32 鍙戣〃璇勮
]]>
Google闈㈣瘯棰?/title><link>http://www.shnenglu.com/Joe/archive/2011/07/14/150924.html</link><dc:creator>simplyzhao</dc:creator><author>simplyzhao</author><pubDate>Thu, 14 Jul 2011 02:13:00 GMT</pubDate><guid>http://www.shnenglu.com/Joe/archive/2011/07/14/150924.html</guid><wfw:comment>http://www.shnenglu.com/Joe/comments/150924.html</wfw:comment><comments>http://www.shnenglu.com/Joe/archive/2011/07/14/150924.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/Joe/comments/commentRss/150924.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/Joe/services/trackbacks/150924.html</trackback:ping><description><![CDATA[<div>鏉ユ簮:<br /><a >http://coolshell.cn/articles/3345.html</a><br /><br /> <div><strong>Software Engineer</strong></div> <div> <div> <ul><li>Why are manhole covers round? 錛堥檲鐨擄細涓轟粈涔堜笅姘翠簳鐩栨槸鍦嗙殑錛熻繖鏄湁N縐嶇瓟妗堢殑錛屼笂Wiki鐪嬬湅鍚э級</li><li>What is the difference between a mutex and a semaphore? Which one would you use to protect access to an increment operation?</li><li>A man pushed his car to a hotel and lost his fortune. What happened? 錛堥檲鐨擄細鑴戠瓔鎬ヨ漿寮紵浠栧湪鐜╁ぇ瀵岀縼娓告垙錛燂紒錛侊級</li><li>Explain the significance of “dead beef”.錛堥檲鐨擄細瑕佹槸浣犵湅鍒扮殑鏄?6榪涘埗 DEAD BEEF錛屼綘浼氳寰楄繖鏄粈涔堬紵IPv6鐨勫湴鍧錛燂級</li><li>Write a C program which measures the the speed of a context switch on a UNIX/Linux system.</li><li>Given a function which produces a random integer in the range 1 to 5, write a function which produces a random integer in the range 1 to 7.錛堥檲鐨擄細涓奡tackOverflow鐪嬬湅鍚э紝緇忓吀鐨勯棶棰橈級</li><li>Describe the algorithm for a depth-first graph traversal.</li><li>Design a class library for writing card games. 錛堥檲鐨擄細鐢ㄤ竴緋誨垪鐨勭被鏉ヨ璁′竴涓墤鍏嬫父鎴忥紝璁捐棰橈級</li><li>You need to check that your friend, Bob, has your correct phone number, but you cannot ask him directly. You must write a the question on a card which and give it to Eve who will take the card to Bob and return the answer to you. What must you write on the card, besides the question, to ensure Bob can encode the message so that Eve cannot read your phone number?錛堥檲鐨擄細鍗忚+鏁板瓧鍔犲瘑錛屾垜璇曟兂浜嗕竴涓紝綰告潯涓婂彲浠ヨ繖鏍峰啓錛?#8220;Bob錛岃鎶婃垜鐨勬墜鏈哄彿浠D5綆楁硶鍔犲瘑鍚庣殑瀛楃涓詫紝姣斿涓嬮潰鐨勫瓧絎︿覆——XXXXXX錛屽畠浠槸涓鏍風殑鍚楋紵”錛?/li><li>How are cookies passed in the HTTP protocol?</li><li>Design the SQL database tables for a car rental database.</li><li>Write a regular expression which matches a email address. 錛堥檲鐨擄細涓奡tackOverflow鏌ョ浉褰撶殑闂鍚с傦級</li><li>Write a function f(a, b) which takes two character string arguments and returns a string containing only the characters found in both strings in the order of a. Write a version which is order N-squared and one which is order N.錛堥檲鐨擄細綆楁硶棰橈紝涓嶉毦錛屼笉璇翠簡銆備竴涓狾(n^2)鍜屼竴涓狾(n)鐨勭畻娉曞鏉傚害錛?/li><li>You are given a the source to a application which is crashing when run. After running it 10 times in a debugger, you find it never crashes in the same place. The application is single threaded, and uses only the C standard library. What programming errors could be causing this crash? How would you test each one? 錛堥檲鐨擄細鍜岄殢鏈烘暟鏈夊叧緋伙紵鎴栨槸鏃墮棿錛燂級</li><li>Explain how congestion control works in the TCP protocol.</li><li>In Java, what is the difference between final, finally, and finalize?</li><li>What is multithreaded programming? What is a deadlock?</li><li>Write a function (with helper functions if needed) called to Excel that takes an excel column value (A,B,C,D…AA,AB,AC,… AAA..) and returns a corresponding integer value (A=1,B=2,… AA=26..).</li><li>You have a stream of infinite queries (ie: real time Google search queries that people are entering). Describe how you would go about finding a good estimate of 1000 samples from this never ending set of data and then write code for it.</li><li>Tree search algorithms. Write BFS and DFS code, explain run time and space requirements. Modify the code to handle trees with weighted edges and loops with BFS and DFS, make the code print out path to goal state.</li><li>You are given a list of numbers. When you reach the end of the list you will come back to the beginning of the list (a circular list). Write the most efficient algorithm to find the minimum # in this list. Find any given # in the list. The numbers in the list are always increasing but you don’t know where the circular list begins, ie: 38, 40, 55, 89, 6, 13, 20, 23, 36. 錛堥檲鐨擄細寰幆鎺掑簭鏁扮粍鐨勪簩鍒嗘煡鎵鵑棶棰橈級</li><li>Describe the data structure that is used to manage memory. (stack)</li><li>What’s the difference between local and global variables?</li><li>If you have 1 million integers, how would you sort them efficiently? (modify a specific sorting algorithm to solve this)</li><li>In Java, what is the difference between static, final, and const. (if you don’t know Java they will ask something similar for C or C++).</li><li>Talk about your class projects or work projects (pick something easy)… then describe how you could make them more efficient (in terms of algorithms).</li><li>Suppose you have an NxN matrix of positive and negative integers. Write some code that finds the sub-matrix with the maximum sum of its elements.錛堥檲鐨擄細浠ュ墠瑙佽繃涓緇存暟緇勭殑榪欎釜闂錛岀幇鍦ㄦ槸浜岀淮鐨勩傛劅瑙夊簲璇ユ槸鎶婁簩緇寸殑絎竴琛岀殑鏈澶у拰鐨勫尯闂寸畻鍑烘潵錛岀劧鍚庡啀鍦ㄨ繖涓熀紜涔嬩笂榪涜浜岀淮鐨勫垎鏋愩傛濊礬搴旇鏄繖涓紝涓嶈繃鍏蜂綋鐨勭畻娉曡繕闇瑕佹兂涓鎯籌級</li><li>Write some code to reverse a string.</li><li>Implement division (without using the divide operator, obviously).錛堥檲鐨擄細鎯充竴鎯蟲墜綆楅櫎娉曠殑榪囩▼銆傦級</li><li>Write some code to find all permutations of the letters in a particular string.</li><li>What method would you use to look up a word in a dictionary? 錛堥檲鐨擄細浣跨敤鎺掑簭錛屽搱甯岋紝鏍戠瓑綆楁硶鍜屾暟鎹粨鏋勶級</li><li>Imagine you have a closet full of shirts. It’s very hard to find a shirt. So what can you do to organize your shirts for easy retrieval?</li><li>You have eight balls all of the same size. 7 of them weigh the same, and one of them weighs slightly more. How can you fine the ball that is heavier by using a balance and only two weighings?</li><li>What is the C-language command for opening a connection with a foreign host over the internet?</li><li>Design and describe a system/application that will most efficiently produce a report of the top 1 million Google search requests. These are the particulars: 1) You are given 12 servers to work with. They are all dual-processor machines with 4Gb of RAM, 4x400GB hard drives and networked together.(Basically, nothing more than high-end PC’s) 2) The log data has already been cleaned for you. It consists of 100 Billion log lines, broken down into 12 320 GB files of 40-byte search terms per line. 3) You can use only custom written applications or available free open-source software.</li><li>There is an array A[N] of N numbers. You have to compose an array Output[N] such that Output[i] will be equal to multiplication of all the elements of A[N] except A[i]. For example Output[0] will be multiplication of A[1] to A[N-1] and Output[1] will be multiplication of A[0] and from A[2] to A[N-1]. Solve it without division operator and in O(n).錛堥檲鐨擄細娉ㄦ剰鍏朵笉鑳戒嬌鐢ㄩ櫎娉曘傜畻娉曟濊礬鏄繖鏍風殑錛屾妸output[i]=a[i]宸﹁竟鐨勪箻縐?x a[i]鍙寵竟鐨勪箻縐紝鎵浠ワ紝鎴戜滑鍙互鍒嗕袱涓驚鐜紝絎竴嬈″厛鎶夾[i]宸﹁竟鐨勪箻縐斁鍦∣utput[i]涓紝絎簩嬈℃妸A[i]鍙寵竟鐨勪箻縐畻鍑烘潵銆傛垜浠厛鐪嬬涓嬈$殑寰幆錛屼嬌鐢ㄨ凱浠g瘡縐殑鏂瑰紡錛屼唬鐮佸涓嬶細for(r=1; i=0; i<n-1; i++){ Output[i]=r; r*=a[i]; }錛岀湅鏄庣櫧浜嗗惂銆傜浜屾鐨勫驚鐜垜灝變笉璇翠簡錛屾柟娉曚竴鏍風殑銆傦級</li><li>There is a linked list of numbers of length N. N is very large and you don’t know N. You have to write a function that will return k random numbers from the list. Numbers should be completely random. Hint: 1. Use random function rand() (returns a number between 0 and 1) and irand() (return either 0 or 1) 2. It should be done in O(n).錛堥檲鐨擄細鏈鍏跺疄涓嶉毦銆傚湪閬嶅巻閾捐〃鐨勫悓鏃朵竴杈圭敓鎴愰殢鏈烘暟錛屼竴杈硅褰曟渶澶х殑K涓殢鏈烘暟鍜屽叾閾炬帴鍦板潃銆傦級</li><li>Find or determine non existence of a number in a sorted list of N numbers where the numbers range over M, M>> N and N large enough to span multiple disks. Algorithm to beat O(log n) bonus points for constant time algorithm.錛堥檲鐨擄細浣跨敤bitmap錛屽鏋滀竴涓暱鏁村艦鏈?4浣嶏紝閭d箞鎴戜滑鍙互浣跨敤M/64涓猙itmap錛?/li><li>You are given a game of Tic Tac Toe. You have to write a function in which you pass the whole game and name of a player. The function will return whether the player has won the game or not. First you to decide which data structure you will use for the game. You need to tell the algorithm first and then need to write the code. Note: Some position may be blank in the game啷?So your data structure should consider this condition also.</li><li>You are given an array [a1 To an] and we have to construct another array [b1 To bn] where bi = a1*a2*…*an/ai. you are allowed to use only constant space and the time complexity is O(n). No divisions are allowed.錛堥檲鐨擄細鍓嶉潰璇磋繃浜嗭級</li><li>How do you put a Binary Search Tree in an array in a efficient manner. Hint :: If the node is stored at the ith position and its children are at 2i and 2i+1(I mean level order wise)Its not the most efficient way.錛堥檲鐨擄細鎸夐『搴忛亶鍘嗘爲錛?/li><li>How do you find out the fifth maximum element in an Binary Search Tree in efficient manner. Note: You should not use use any extra space. i.e sorting Binary Search Tree and storing the results in an array and listing out the fifth element.</li><li>Given a Data Structure having first n integers and next n chars. A = i1 i2 i3 … iN c1 c2 c3 … cN.Write an in-place algorithm to rearrange the elements of the array ass A = i1 c1 i2 c2 … in cn錛堥檲鐨擄細榪欎釜綆楁硶鍏跺疄灝辨槸浠庝腑闂村紑濮嬩氦鎹㈠厓绱狅紝浠g爜錛歠or(i=n-1; i>1; i++) {  for(j=i; j<2*n-i; j+=2) { swap(a[j], a[j+1]); } }錛屼笉濂芥剰鎬濆啓鍦ㄥ悓涓琛屼笂浜嗐傦級</li><li>Given two sequences of items, find the items whose absolute number increases or decreases the most when comparing one sequence with the other by reading the sequence only once.</li><li>Given That One of the strings is very very long , and the other one could be of various sizes. Windowing will result in O(N+M) solution but could it be better? May be NlogM or even better?</li><li>How many lines can be drawn in a 2D plane such that they are equidistant from 3 non-collinear points?</li><li>Let’s say you have to construct Google maps from scratch and guide a person standing on Gateway of India (Mumbai) to India Gate(Delhi). How do you do the same?</li><li>Given that you have one string of length N and M small strings of length L. How do you efficiently find the occurrence of each small string in the larger one?</li><li>Given a binary tree, programmatically you need to prove it is a binary search tree.</li><li>You are given a small sorted list of numbers, and a very very long sorted list of numbers – so long that it had to be put on a disk in different blocks. How would you find those short list numbers in the bigger one?</li><li>Suppose you have given N companies, and we want to eventually merge them into one big company. How many ways are theres to merge?</li><li>Given a file of 4 billion 32-bit integers, how to find one that appears at least twice? 錛堥檲鐨擄細鎴戣兘鎯沖埌鐨勬槸鎷嗗垎鎴愯嫢騫蹭釜灝忔暟緇勶紝鎺掑簭錛岀劧鍚庝竴鐐圭偣褰掑茍璧鋒潵錛?/li><li>Write a program for displaying the ten most frequent words in a file such that your program should be efficient in all complexity measures.錛堥檲鐨擄細浣犲彲鑳介渶瑕佺湅鐪嬭繖綃囨枃绔?a target="_blank"><span style="text-decoration: underline">Finding Frequent Items in Data Streams</span></a>錛?/li><li>Design a stack. We want to push, pop, and also, retrieve the minimum element in constant time.</li><li>Given a set of coin denominators, find the minimum number of coins to give a certain amount of change.錛堥檲鐨擄細浣犲簲璇ユ煡鐪嬩竴涓嬭繖綃囨枃绔狅細<a target="_blank"><span style="text-decoration: underline">Coin Change Problem</span></a>錛?/li><li>Given an array, i) find the longest continuous increasing subsequence. ii) find the longest increasing subsequence.錛堥檲鐨擄細榪欎釜棰樹笉闅撅紝O(n)綆楁硶鏄竟閬嶅巻杈硅褰曞綋鍓嶆渶澶х殑榪炵畫鐨勯暱搴︺傦級</li><li>Suppose we have N companies, and we want to eventually merge them into one big company. How many ways are there to merge?</li><li>Write a function to find the middle node of a single link list. 錛堥檲鐨擄細鎴戣兘鎯沖埌鐨勭畻娉曟槸——璁劇疆涓や釜鎸囬拡p1鍜宲2錛屾瘡涓嬈★紝p1璧頒袱姝ワ紝p2璧頒竴姝ワ紝榪欐牱錛屽綋p1璧板埌鏈鍚庢椂錛宲2灝卞湪涓棿錛?/li><li>Given two binary trees, write a compare function to check if they are equal or not. Being equal means that they have the same value and same structure.錛堥檲鐨擄細榪欎釜寰堢畝鍗曪紝浣跨敤閫掑綊綆楁硶銆傦級</li><li>Implement put/get methods of a fixed size cache with LRU replacement algorithm.</li><li>You are given with three sorted arrays ( in ascending order), you are required to find a triplet ( one element from each array) such that distance is minimum. Distance is defined like this : If a[i], b[j] and c[k] are three elements then distance=max(abs(a[i]-b[j]),abs(a[i]-c[k]),abs(b[j]-c[k]))” Please give a solution in O(n) time complexity錛堥檲鐨擄細涓変釜鎸囬拡錛宎, b, c鍒嗗埆鎸囧悜涓変釜鏁扮粍澶達紝鍋囪錛歛[0]<b[0]<c[0]錛屾帹榪沘鐩村埌a[i]>b[0]錛岃綆?abs(a[i-1] – c[0])錛屾妸緇撴灉淇濆瓨鍦╩in涓傜幇鍦ㄦ儏鍐靛彉鎴愭壘 a[i], b[0],c[0]錛岄噸澶嶄笂榪拌繃紼嬶紝濡傛灉鏈変竴涓柊鐨勫兼瘮min瑕佸皬錛岄偅灝卞彇浠g幇鏈夌殑min銆傦級</li><li>How does C++ deal with constructors and deconstructors of a class and its child class?</li><li>Write a function that flips the bits inside a byte (either in C++ or Java). Write an algorithm that take a list of n words, and an integer m, and retrieves the mth most frequent word in that list.</li><li>What’s 2 to the power of 64?</li><li>Given that you have one string of length N and M small strings of length L. How do you efficiently find the occurrence of each small string in the larger one? 錛堥檲鐨擄細鎴戣兘鎯沖埌鐨勬槸——鎶婇偅M涓皬瀛椾覆鎺掍釜搴忥紝鐒跺悗閬嶅巻澶у瓧涓詫紝騫跺湪閭涓瓧涓蹭腑浠ヤ簩鍒嗗彇涓殑鏂瑰紡鏌ユ壘銆傦級</li><li>How do you find out the fifth maximum element in an Binary Search Tree in efficient manner.</li><li>Suppose we have N companies, and we want to eventually merge them into one big company. How many ways are there to merge?</li><li>There is linked list of millions of node and you do not know the length of it. Write a function which will return a random number from the list.</li><li>You need to check that your friend, Bob, has your correct phone number, but you cannot ask him directly. You must write a the question on a card which and give it to Eve who will take the card to Bob and return the answer to you. What must you write on the card, besides the question, to ensure Bob can encode the message so that Eve cannot read your phone number?</li><li>How long it would take to sort 1 trillion numbers? Come up with a good estimate.</li><li>Order the functions in order of their asymptotic performance: 1) 2^n 2) n^100 3) n! 4) n^n</li><li>There are some data represented by(x,y,z). Now we want to find the Kth least data. We say (x1, y1, z1) > (x2, y2, z2) when value(x1, y1, z1) > value(x2, y2, z2) where value(x,y,z) = (2^x)*(3^y)*(5^z). Now we can not get it by calculating value(x,y,z) or through other indirect calculations as lg(value(x,y,z)). How to solve it?</li><li>How many degrees are there in the angle between the hour and minute hands of a clock when the time is a quarter past three?</li><li>Given an array whose elements are sorted, return the index of a the first occurrence of a specific integer. Do this in sub-linear time. I.e. do not just go through each element searching for that element.</li><li>Given two linked lists, return the intersection of the two lists: i.e. return a list containing only the elements that occur in both of the input lists. 錛堥檲鐨擄細鎶婄涓涓摼琛ㄥ瓨鍏ash琛紝鐒跺悗閬嶅巻絎簩涓摼琛ㄣ備笉鐭ラ亾榪樻病鏈夋洿濂界殑鏂規硶銆傦級</li><li>What’s the difference between a hashtable and a hashmap?</li><li>If a person dials a sequence of numbers on the telephone, what possible words/strings can be formed from the letters associated with those numbers?錛堥檲鐨擄細榪欎釜闂鍜岀編鍥界殑鐢佃瘽鏈夊叧緋伙紝澶у鍙互璇曠潃鎯充竴涓嬫垜浠彂鐭俊鐨勬墜鏈猴紝鎸夋暟瀛楅敭鍑哄瓧姣嶏紝涓涓粍鍚堢殑鏁板闂銆傦級</li><li>How would you reverse the image on an n by n matrix where each pixel is represented by a bit?</li><li>Create a fast cached storage mechanism that, given a limitation on the amount of cache memory, will ensure that only the least recently used items are discarded when the cache memory is reached when inserting a new item. It supports 2 functions: String get(T t) and void put(String k, T t).</li><li>Create a cost model that allows Google to make purchasing decisions on to compare the cost of purchasing more RAM memory for their servers vs. buying more disk space.</li><li>Design an algorithm to play a game of Frogger and then code the solution. The object of the game is to direct a frog to avoid cars while crossing a busy road. You may represent a road lane via an array. Generalize the solution for an N-lane road.</li><li>What sort would you use if you had a large data set on disk and a small amount of ram to work with?</li><li>What sort would you use if you required tight max time bounds and wanted highly regular performance.</li><li>How would you store 1 million phone numbers?錛堥檲鐨擄細璇曟兂鐢佃瘽鏄湁鍖烘鐨勶紝鍙互鎶婂尯孌電粺涓淇濆瓨錛孎lyweight璁捐妯″紡錛?/li><li>Design a 2D dungeon crawling game. It must allow for various items in the maze – walls, objects, and computer-controlled characters. (The focus was on the class structures, and how to optimize the experience for the user as s/he travels through the dungeon.)</li><li>What is the size of the C structure below on a 32-bit system? On a 64-bit? 錛堥檲鐨擄細娉ㄦ剰緙栬瘧鍣ㄧ殑瀵歸綈錛?</li></ul> <p style="padding-left: 90px">struct foo {</p> <div style="padding-left: 90px">char a;</div> <div style="padding-left: 90px">char* b;</div> <div style="padding-left: 90px">};</div></div></div></div><img src ="http://www.shnenglu.com/Joe/aggbug/150924.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/Joe/" target="_blank">simplyzhao</a> 2011-07-14 10:13 <a href="http://www.shnenglu.com/Joe/archive/2011/07/14/150924.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鎵戝厠鐗岀殑欏哄瓙http://www.shnenglu.com/Joe/archive/2011/07/12/150787.htmlsimplyzhaosimplyzhaoTue, 12 Jul 2011 12:33:00 GMThttp://www.shnenglu.com/Joe/archive/2011/07/12/150787.htmlhttp://www.shnenglu.com/Joe/comments/150787.htmlhttp://www.shnenglu.com/Joe/archive/2011/07/12/150787.html#Feedback0http://www.shnenglu.com/Joe/comments/commentRss/150787.htmlhttp://www.shnenglu.com/Joe/services/trackbacks/150787.html棰樼洰鏉ユ簮:
http://zhedahht.blog.163.com/blog/static/25411174200951262930831/

 棰樼洰錛氫粠鎵戝厠鐗屼腑闅忔満鎶?/span>5寮犵墝錛屽垽鏂槸涓嶆槸涓涓『瀛愶紝鍗寵繖5寮犵墝鏄笉鏄繛緇殑銆?/span>2-10涓烘暟瀛楁湰韜紝A涓?/span>1錛?/span>J涓?/span>11錛?/span>Q涓?/span>12錛?/span>K涓?/span>13錛岃屽ぇ灝忕帇鍙互鐪嬫垚浠繪剰鏁板瓧銆?/span>

鎬濊礬涓:
鎴戜滑闇瑕佹妸鎵戝厠鐗岀殑鑳屾櫙鎶借薄鎴愯綆楁満璇█銆備笉闅炬兂璞★紝鎴戜滑鍙互鎶?/span>5寮犵墝鐪嬫垚鐢?/span>5涓暟瀛楃粍鎴愮殑鏁扮粍銆傚ぇ灝忕帇鏄壒孌婄殑鏁板瓧錛屾垜浠笉濡ㄦ妸瀹冧滑閮藉綋鎴?/span>0錛岃繖鏍峰拰鍏朵粬鎵戝厠鐗屼唬琛ㄧ殑鏁板瓧灝變笉閲嶅浜嗐?/span>

鎺ヤ笅鏉ユ垜浠潵鍒嗘瀽鎬庢牱鍒ゆ柇5涓暟瀛楁槸涓嶆槸榪炵畫鐨勩傛渶鐩磋鐨勬槸錛屾垜浠妸鏁扮粍鎺掑簭銆備絾鍊煎緱娉ㄦ剰鐨勬槸錛岀敱浜?/span>0鍙互褰撴垚浠繪剰鏁板瓧錛屾垜浠彲浠ョ敤0鍘昏ˉ婊℃暟緇勪腑鐨勭┖緙恒備篃灝辨槸鎺掑簭涔嬪悗鐨勬暟緇勪笉鏄繛緇殑錛屽嵆鐩擱偦鐨勪袱涓暟瀛楃浉闅旇嫢騫蹭釜鏁板瓧錛屼絾濡傛灉鎴戜滑鏈夎凍澶熺殑0鍙互琛ユ弧榪欎袱涓暟瀛楃殑絀虹己錛岃繖涓暟緇勫疄闄呬笂榪樻槸榪炵畫鐨勩備婦涓緥瀛愶紝鏁扮粍鎺掑簭涔嬪悗涓?/span>{0錛?/span>1錛?/span>3錛?/span>4錛?/span>5}銆傚湪1鍜?/span>3涔嬮棿絀虹己浜嗕竴涓?/span>2錛屽垰濂芥垜浠湁涓涓?/span>0錛屼篃灝辨槸鎴戜滑鍙互瀹冨綋鎴?/span>2鍘誨~琛ヨ繖涓┖緙恒?/span>

浜庢槸鎴戜滑闇瑕佸仛涓変歡浜嬫儏錛氭妸鏁扮粍鎺掑簭錛岀粺璁℃暟緇勪腑0鐨勪釜鏁幫紝緇熻鎺掑簭涔嬪悗鐨勬暟緇勭浉閭繪暟瀛椾箣闂寸殑絀虹己鎬繪暟銆傚鏋滅┖緙虹殑鎬繪暟灝忎簬鎴栬呯瓑浜?/span>0鐨勪釜鏁幫紝閭d箞榪欎釜鏁扮粍灝辨槸榪炵畫鐨勶紱鍙嶄箣鍒欎笉榪炵畫銆傛渶鍚庯紝鎴戜滑榪橀渶瑕佹敞鎰忕殑鏄紝濡傛灉鏁扮粍涓殑闈?/span>0鏁板瓧閲嶅鍑虹幇錛屽垯璇ユ暟緇勪笉鏄繛緇殑銆傛崲鎴愭墤鍏嬬墝鐨勬弿榪版柟寮忥紝灝辨槸濡傛灉涓鍓墝閲屽惈鏈夊瀛愶紝鍒欎笉鍙兘鏄『瀛愩?br />
鏇村ソ鐨勬濊礬浜?
1錛夌‘璁?寮犵墝涓櫎浜?錛屽叾浣欐暟瀛楁病鏈夐噸澶嶇殑錛堝彲浠ョ敤琛ㄧ粺璁$殑鏂規硶錛?
2) 婊¤凍榪欐牱鐨勯昏緫錛氾紙max錛宮in鍒嗗埆浠h〃5寮犵墝涓殑闄?浠ュ鐨勬渶澶у兼渶灝忓鹼級
       濡傛灉娌℃湁0錛屽垯max-min=4錛屽垯涓洪『瀛愶紝鍚﹀垯涓嶆槸
       濡傛灉鏈変竴涓?錛屽垯max-min=4鎴栬?錛屽垯涓洪『瀛愶紝鍚﹀垯涓嶆槸
       濡傛灉鏈変袱涓?錛屽垯max-min=4鎴栬?鎴栬?錛屽垯涓洪『瀛愶紝鍚﹀垯涓嶆槸

鏈澶у煎拰鏈灝忓煎湪1錛変腑灝卞彲浠ヨ幏寰楋紝榪欐牱灝變笉鐢ㄦ帓搴忎簡




]]>
C++鍩虹棰?/title><link>http://www.shnenglu.com/Joe/archive/2011/06/22/149205.html</link><dc:creator>simplyzhao</dc:creator><author>simplyzhao</author><pubDate>Wed, 22 Jun 2011 11:41:00 GMT</pubDate><guid>http://www.shnenglu.com/Joe/archive/2011/06/22/149205.html</guid><wfw:comment>http://www.shnenglu.com/Joe/comments/149205.html</wfw:comment><comments>http://www.shnenglu.com/Joe/archive/2011/06/22/149205.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/Joe/comments/commentRss/149205.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/Joe/services/trackbacks/149205.html</trackback:ping><description><![CDATA[<div>棰樼洰鏉ユ簮:<br /><a >http://zhedahht.blog.163.com/blog/static/25411174201102642136998/<br /><br /></a> <p style="margin: 0in 0in 10pt"><strong><span style="font-family: '瀹嬩綋', 'serif'">棰樼洰錛堝叚錛夛細</span></strong><span style="font-family: '瀹嬩綋', 'serif'">榪愯涓嬪垪</span>C++<span style="font-family: '瀹嬩綋', 'serif'">浠g爜錛岃緭鍑轟粈涔堬紵</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? color: blue; font-size: 9pt">struct</span><span style="font-family: 鏂板畫浣? font-size: 9pt"> Point3D</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">{</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        <span style="color: blue">int</span> x;</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        <span style="color: blue">int</span> y;</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        <span style="color: blue">int</span> z;</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">};</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"> </p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? color: blue; font-size: 9pt">int</span><span style="font-family: 鏂板畫浣? font-size: 9pt"> _tmain(<span style="color: blue">int</span> argc, _TCHAR* argv[])</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">{</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        Point3D* pPoint = NULL;</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        <span style="color: blue">int</span> offset = (<span style="color: blue">int</span>)(&(pPoint)->z);</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"> </p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        printf(<span style="color: #a31515">"%d"</span>, offset);</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        <span style="color: blue">return</span> 0;</span></p> <p style="margin: 0in 0in 10pt"><span style="line-height: 115%; font-family: 鏂板畫浣? font-size: 9pt">}</span></p> <p style="margin: 0in 0in 10pt"><strong><span style="font-family: '瀹嬩綋', 'serif'">絳旀錛?/span></strong><span style="font-family: '瀹嬩綋', 'serif'">杈撳嚭</span>8<span style="font-family: '瀹嬩綋', 'serif'">銆傜敱浜庡湪</span>pPoint->z<span style="font-family: '瀹嬩綋', 'serif'">鐨勫墠闈㈠姞涓婁簡鍙栧湴鍧絎﹀彿錛岃繍琛屽埌姝ゆ椂鐨勬椂鍊欙紝浼氬湪</span>pPoint<span style="font-family: '瀹嬩綋', 'serif'">鐨勬寚閽堝湴鍧涓婂姞</span>z<span style="font-family: '瀹嬩綋', 'serif'">鍦ㄧ被鍨?/span>Point3D<span style="font-family: '瀹嬩綋', 'serif'">涓殑鍋忕Щ閲?/span>8<span style="font-family: '瀹嬩綋', 'serif'">銆傜敱浜?/span>pPoint<span style="font-family: '瀹嬩綋', 'serif'">鐨勫湴鍧鏄?/span>0<span style="font-family: '瀹嬩綋', 'serif'">錛屽洜姝ゆ渶緇?/span>offset<span style="font-family: '瀹嬩綋', 'serif'">鐨勫兼槸</span>8<span style="font-family: '瀹嬩綋', 'serif'">銆?/span></p> <p style="text-indent: 0.5in; margin: 0in 0in 10pt">&(pPoint->z)<span style="font-family: '瀹嬩綋', 'serif'">鐨勮鎰忔槸姹?/span>pPoint<span style="font-family: '瀹嬩綋', 'serif'">涓彉閲?/span>z<span style="font-family: '瀹嬩綋', 'serif'">鐨勫湴鍧錛?/span>pPoint<span style="font-family: '瀹嬩綋', 'serif'">鐨勫湴鍧</span>0<span style="font-family: '瀹嬩綋', 'serif'">鍔?/span>z<span style="font-family: '瀹嬩綋', 'serif'">鐨勫亸縐婚噺</span>8<span style="font-family: '瀹嬩綋', 'serif'">錛夛紝騫朵笉闇瑕佽闂?/span>pPoint<span style="font-family: '瀹嬩綋', 'serif'">鎸囧悜鐨勫唴瀛樸傚彧瑕佷笉璁塊棶闈炴硶鐨勫唴瀛橈紝紼嬪簭灝變笉浼氬嚭閿欍?/span></p> <p style="margin: 0in 0in 10pt"><strong><span style="font-family: '瀹嬩綋', 'serif'">棰樼洰錛堜竷錛夛細</span></strong><span style="font-family: '瀹嬩綋', 'serif'">榪愯涓嬪垪</span>C++<span style="font-family: '瀹嬩綋', 'serif'">浠g爜錛岃緭鍑轟粈涔堬紵</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? color: blue; font-size: 9pt">class</span><span style="font-family: 鏂板畫浣? font-size: 9pt"> A</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">{</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? color: blue; font-size: 9pt">public</span><span style="font-family: 鏂板畫浣? font-size: 9pt">:</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        A()</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        {</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">                Print();</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        }</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        <span style="color: blue">virtual</span> <span style="color: blue">void</span> Print()</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        {</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">                printf(<span style="color: #a31515">"A is constructed.\n"</span>);</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        }</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">};</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"> </p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? color: blue; font-size: 9pt">class</span><span style="font-family: 鏂板畫浣? font-size: 9pt"> B: <span style="color: blue">public</span> A</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">{</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? color: blue; font-size: 9pt">public</span><span style="font-family: 鏂板畫浣? font-size: 9pt">:</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        B()</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        {</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">                Print();</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        }</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"> </p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        <span style="color: blue">virtual</span> <span style="color: blue">void</span> Print()</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        {</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">                printf(<span style="color: #a31515">"B is constructed.\n"</span>);</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        }</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">};</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"> </p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? color: blue; font-size: 9pt">int</span><span style="font-family: 鏂板畫浣? font-size: 9pt"> _tmain(<span style="color: blue">int</span> argc, _TCHAR* argv[])</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">{</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        A* pA = <span style="color: blue">new</span> B();</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        <span style="color: blue">delete</span> pA;</span></p> <p style="line-height: normal; margin: 0in 0in 0pt"> </p> <p style="line-height: normal; margin: 0in 0in 0pt"><span style="font-family: 鏂板畫浣? font-size: 9pt">        <span style="color: blue">return</span> 0;</span></p> <p style="margin: 0in 0in 10pt"><span style="line-height: 115%; font-family: 鏂板畫浣? font-size: 9pt">}</span></p> <p style="margin: 0in 0in 10pt"><strong><span style="font-family: '瀹嬩綋', 'serif'">絳旀錛?/span></strong><span style="font-family: '瀹嬩綋', 'serif'">鍏堝悗鎵撳嵃鍑轟袱琛?/span>:A is constructed. B is constructed. <span style="font-family: '瀹嬩綋', 'serif'">璋冪敤</span>B<span style="font-family: '瀹嬩綋', 'serif'">鐨勬瀯閫犲嚱鏁版椂錛屽厛浼氳皟鐢?/span>B<span style="font-family: '瀹嬩綋', 'serif'">鐨勫熀綾誨強</span>A<span style="font-family: '瀹嬩綋', 'serif'">鐨勬瀯閫犲嚱鏁般傜劧鍚庡湪</span>A<span style="font-family: '瀹嬩綋', 'serif'">鐨勬瀯閫犲嚱鏁伴噷璋冪敤</span>Print<span style="font-family: '瀹嬩綋', 'serif'">銆傜敱浜庢鏃跺疄渚嬬殑綾誨瀷</span>B<span style="font-family: '瀹嬩綋', 'serif'">鐨勯儴鍒嗚繕娌℃湁鏋勯犲ソ錛屾湰璐ㄤ笂瀹冨彧鏄?/span>A<span style="font-family: '瀹嬩綋', 'serif'">鐨勪竴涓疄渚嬶紝浠栫殑铏氬嚱鏁拌〃鎸囬拡鎸囧悜鐨勬槸綾誨瀷</span>A<span style="font-family: '瀹嬩綋', 'serif'">鐨勮櫄鍑芥暟琛ㄣ傚洜姝ゆ鏃惰皟鐢ㄧ殑</span>Print<span style="font-family: '瀹嬩綋', 'serif'">鏄?/span>A::Print<span style="font-family: '瀹嬩綋', 'serif'">錛岃屼笉鏄?/span>B::Print<span style="font-family: '瀹嬩綋', 'serif'">銆傛帴鐫璋冪敤綾誨瀷</span>B<span style="font-family: '瀹嬩綋', 'serif'">鐨勬瀯閫犲嚱鏁幫紝騫惰皟鐢?/span>Print<span style="font-family: '瀹嬩綋', 'serif'">銆傛鏃跺凡緇忓紑濮嬫瀯閫?/span>B<span style="font-family: '瀹嬩綋', 'serif'">錛屽洜姝ゆ鏃惰皟鐢ㄧ殑</span>Print<span style="font-family: '瀹嬩綋', 'serif'">鏄?/span>B::Print<span style="font-family: '瀹嬩綋', 'serif'">銆?/span></p> <p style="text-indent: 0.5in; margin: 0in 0in 10pt"><span style="font-family: '瀹嬩綋', 'serif'">鍚屾牱鏄皟鐢ㄨ櫄鎷熷嚱鏁?/span>Print<span style="font-family: '瀹嬩綋', 'serif'">錛屾垜浠彂鐜板湪綾誨瀷</span>A<span style="font-family: '瀹嬩綋', 'serif'">鐨勬瀯閫犲嚱鏁頒腑錛岃皟鐢ㄧ殑鏄?/span>A::Print<span style="font-family: '瀹嬩綋', 'serif'">錛屽湪</span>B<span style="font-family: '瀹嬩綋', 'serif'">鐨勬瀯閫犲嚱鏁頒腑錛岃皟鐢ㄧ殑鏄?/span>B::Print<span style="font-family: '瀹嬩綋', 'serif'">銆傚洜姝よ櫄鍑芥暟鍦ㄦ瀯閫犲嚱鏁頒腑錛屽凡緇忓け鍘諱簡铏氬嚱鏁扮殑鍔ㄦ佺粦瀹氱壒鎬с?/span></p><br /><br /></div><img src ="http://www.shnenglu.com/Joe/aggbug/149205.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/Joe/" target="_blank">simplyzhao</a> 2011-06-22 19:41 <a href="http://www.shnenglu.com/Joe/archive/2011/06/22/149205.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>欏烘椂閽堟墦鍗扮煩闃?/title><link>http://www.shnenglu.com/Joe/archive/2011/06/17/148879.html</link><dc:creator>simplyzhao</dc:creator><author>simplyzhao</author><pubDate>Fri, 17 Jun 2011 12:00:00 GMT</pubDate><guid>http://www.shnenglu.com/Joe/archive/2011/06/17/148879.html</guid><wfw:comment>http://www.shnenglu.com/Joe/comments/148879.html</wfw:comment><comments>http://www.shnenglu.com/Joe/archive/2011/06/17/148879.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/Joe/comments/commentRss/148879.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/Joe/services/trackbacks/148879.html</trackback:ping><description><![CDATA[<div>棰樼洰鏉ユ簮:<br /><a >http://zhedahht.blog.163.com/blog/static/254111742010111112236313/</a><br /><br />妯℃嫙娉? <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#include</span><span style="color: #000000"><</span><span style="color: #000000">stdio.h</span><span style="color: #000000">></span><span style="color: #000000"><br /></span><span style="color: #0000ff">#define</span><span style="color: #000000"> MAX_LEN 101</span><span style="color: #000000"><br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000"><br />print_circle(</span><span style="color: #0000ff">int</span><span style="color: #000000"> (</span><span style="color: #000000">*</span><span style="color: #000000">mtrx)[MAX_LEN], </span><span style="color: #0000ff">int</span><span style="color: #000000"> leftup_x, </span><span style="color: #0000ff">int</span><span style="color: #000000"> leftup_y, </span><span style="color: #0000ff">int</span><span style="color: #000000"> rightdown_x, </span><span style="color: #0000ff">int</span><span style="color: #000000"> rightdown_y)<br />{<br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> i, j;<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(leftup_x </span><span style="color: #000000">==</span><span style="color: #000000"> rightdown_x) {<br />        </span><span style="color: #0000ff">for</span><span style="color: #000000">(j</span><span style="color: #000000">=</span><span style="color: #000000">leftup_y; j</span><span style="color: #000000"><=</span><span style="color: #000000">rightdown_y; j</span><span style="color: #000000">++</span><span style="color: #000000">)<br />            printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\t</span><span style="color: #000000">"</span><span style="color: #000000">, mtrx[leftup_x][j]);<br />        </span><span style="color: #0000ff">return</span><span style="color: #000000">;<br />    }<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(leftup_y </span><span style="color: #000000">==</span><span style="color: #000000"> rightdown_y) {<br />        </span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">leftup_x; i</span><span style="color: #000000"><=</span><span style="color: #000000">rightdown_x; i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />            printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\t</span><span style="color: #000000">"</span><span style="color: #000000">, mtrx[i][leftup_y]);<br />        </span><span style="color: #0000ff">return</span><span style="color: #000000">;<br />    }<br /><br />    </span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">leftup_y; i</span><span style="color: #000000"><</span><span style="color: #000000">rightdown_y; i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />        printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\t</span><span style="color: #000000">"</span><span style="color: #000000">, mtrx[leftup_x][i]);<br />    </span><span style="color: #0000ff">for</span><span style="color: #000000">(j</span><span style="color: #000000">=</span><span style="color: #000000">leftup_x; j</span><span style="color: #000000"><</span><span style="color: #000000">rightdown_x; j</span><span style="color: #000000">++</span><span style="color: #000000">)<br />        printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\t</span><span style="color: #000000">"</span><span style="color: #000000">, mtrx[j][rightdown_y]);<br />    </span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">rightdown_y; i</span><span style="color: #000000">></span><span style="color: #000000">leftup_y; i</span><span style="color: #000000">--</span><span style="color: #000000">)<br />        printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\t</span><span style="color: #000000">"</span><span style="color: #000000">, mtrx[rightdown_x][i]);<br />    </span><span style="color: #0000ff">for</span><span style="color: #000000">(j</span><span style="color: #000000">=</span><span style="color: #000000">rightdown_x; j</span><span style="color: #000000">></span><span style="color: #000000">leftup_x; j</span><span style="color: #000000">--</span><span style="color: #000000">)<br />        printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\t</span><span style="color: #000000">"</span><span style="color: #000000">, mtrx[j][leftup_y]);<br />}<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000"><br />solve(</span><span style="color: #0000ff">int</span><span style="color: #000000"> (</span><span style="color: #000000">*</span><span style="color: #000000">mtrx)[MAX_LEN], </span><span style="color: #0000ff">int</span><span style="color: #000000"> width, </span><span style="color: #0000ff">int</span><span style="color: #000000"> length)<br />{<br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> lu_x, lu_y, rd_x, rd_y;<br />    lu_x </span><span style="color: #000000">=</span><span style="color: #000000"> lu_y </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br />    rd_x </span><span style="color: #000000">=</span><span style="color: #000000"> width</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;<br />    rd_y </span><span style="color: #000000">=</span><span style="color: #000000"> length</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">;<br />    </span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">1</span><span style="color: #000000">) {<br />        </span><span style="color: #0000ff">if</span><span style="color: #000000">(lu_x</span><span style="color: #000000">></span><span style="color: #000000">rd_x </span><span style="color: #000000">||</span><span style="color: #000000"> lu_y</span><span style="color: #000000">></span><span style="color: #000000">rd_y)<br />            </span><span style="color: #0000ff">break</span><span style="color: #000000">;<br />        print_circle(mtrx, lu_x, lu_y, rd_x, rd_y);<br />        </span><span style="color: #000000">++</span><span style="color: #000000">lu_x;<br />        </span><span style="color: #000000">++</span><span style="color: #000000">lu_y;<br />        </span><span style="color: #000000">--</span><span style="color: #000000">rd_x;<br />        </span><span style="color: #000000">--</span><span style="color: #000000">rd_y;<br />    }<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000"><br />main(</span><span style="color: #0000ff">int</span><span style="color: #000000"> argc, </span><span style="color: #0000ff">char</span><span style="color: #000000"> </span><span style="color: #000000">**</span><span style="color: #000000">argv)<br />{<br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> i, j, length, width, matrix[MAX_LEN][MAX_LEN];<br />    scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d %d</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">&</span><span style="color: #000000">width, </span><span style="color: #000000">&</span><span style="color: #000000">length);<br />    </span><span style="color: #0000ff">for</span><span style="color: #000000">(i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">; i</span><span style="color: #000000"><</span><span style="color: #000000">width; i</span><span style="color: #000000">++</span><span style="color: #000000">)<br />        </span><span style="color: #0000ff">for</span><span style="color: #000000">(j</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">; j</span><span style="color: #000000"><</span><span style="color: #000000">length; j</span><span style="color: #000000">++</span><span style="color: #000000">)<br />            scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d</span><span style="color: #000000">"</span><span style="color: #000000">, matrix[i]</span><span style="color: #000000">+</span><span style="color: #000000">j);<br /><br />    solve(matrix, width, length);<br />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div><br /><br /></div><img src ="http://www.shnenglu.com/Joe/aggbug/148879.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/Joe/" target="_blank">simplyzhao</a> 2011-06-17 20:00 <a href="http://www.shnenglu.com/Joe/archive/2011/06/17/148879.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>涓嶇敤錛嬨侊紞銆伱椼伱鋒暟瀛楄繍綆楃鍋氬姞娉?/title><link>http://www.shnenglu.com/Joe/archive/2011/06/17/148874.html</link><dc:creator>simplyzhao</dc:creator><author>simplyzhao</author><pubDate>Fri, 17 Jun 2011 09:30:00 GMT</pubDate><guid>http://www.shnenglu.com/Joe/archive/2011/06/17/148874.html</guid><wfw:comment>http://www.shnenglu.com/Joe/comments/148874.html</wfw:comment><comments>http://www.shnenglu.com/Joe/archive/2011/06/17/148874.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/Joe/comments/commentRss/148874.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/Joe/services/trackbacks/148874.html</trackback:ping><description><![CDATA[<div>棰樼洰鏉ユ簮:<br /><a >http://zhedahht.blog.163.com/blog/static/254111742011125100605/</a> <p style="margin: 0in 0in 10pt"><strong><span style="font-family: 瀹嬩綋">棰樼洰錛氬啓涓涓嚱鏁幫紝姹備袱涓暣鏁扮殑涔嬪拰錛岃姹傚湪鍑芥暟浣撳唴涓嶅緱浣跨敤錛嬨侊紞銆?#215;銆?#247;銆?/span></strong></p> <p style="margin: 0in 0in 10pt"><span style="font-family: 瀹嬩綋">鍒嗘瀽錛氳繖鍙堟槸涓閬撹冨療鍙戞暎鎬濈淮鐨勫緢鏈夋剰鎬濈殑棰樼洰銆傚綋鎴戜滑涔犱互涓哄父鐨勪笢瑗胯闄愬埗浣跨敤鐨勬椂鍊欙紝濡備綍紿佺牬甯歌鍘繪濊冿紝灝辨槸瑙e喅榪欎釜闂鐨勫叧閿墍鍦ㄣ?/span></p> <p style="text-indent: 0.5in; margin: 0in 0in 10pt"><span style="font-family: 瀹嬩綋">鐪嬪埌鐨勮繖涓鐩紝鎴戠殑絎竴鍙嶅簲鏄偦鐪間簡錛屽洓鍒欒繍綆楅兘涓嶈兘鐢紝閭h繕鑳界敤浠涔堝晩錛熷彲鏄棶棰樻繪槸瑕佽В鍐崇殑錛屽彧鑳芥墦寮鎬濊礬鍘繪濊冨悇縐嶅彲鑳芥с傞鍏堟垜浠彲浠ュ垎鏋愪漢浠槸濡備綍鍋氬崄榪涘埗鐨勫姞娉曠殑錛屾瘮濡傛槸濡備綍寰楀嚭</span>5+17=22<span style="font-family: 瀹嬩綋">榪欎釜緇撴灉鐨勩傚疄闄呬笂錛屾垜浠彲浠ュ垎鎴愪笁姝ョ殑錛氱涓姝ュ彧鍋氬悇浣嶇浉鍔犱笉榪涗綅錛屾鏃剁浉鍔犵殑緇撴灉鏄?/span>12<span style="font-family: 瀹嬩綋">錛堜釜浣嶆暟</span>5<span style="font-family: 瀹嬩綋">鍜?/span>7<span style="font-family: 瀹嬩綋">鐩稿姞涓嶈榪涗綅鏄?/span>2<span style="font-family: 瀹嬩綋">錛屽崄浣嶆暟</span>0<span style="font-family: 瀹嬩綋">鍜?/span>1<span style="font-family: 瀹嬩綋">鐩稿姞緇撴灉鏄?/span>1<span style="font-family: 瀹嬩綋">錛夛紱絎簩姝ュ仛榪涗綅錛?/span>5+7<span style="font-family: 瀹嬩綋">涓湁榪涗綅錛岃繘浣嶇殑鍊兼槸</span>10<span style="font-family: 瀹嬩綋">錛涚涓夋鎶婂墠闈袱涓粨鏋滃姞璧鋒潵錛?/span>12+10<span style="font-family: 瀹嬩綋">鐨勭粨鏋滄槸</span>22<span style="font-family: 瀹嬩綋">錛屽垰濂?/span>5+17=22<span style="font-family: 瀹嬩綋">銆?/span></p> <p style="text-indent: 0.5in; margin: 0in 0in 10pt"><span style="font-family: 瀹嬩綋">鍓嶉潰鎴戜滑灝卞湪鎯籌紝姹備袱鏁頒箣鍜屽洓鍒欒繍綆楅兘涓嶈兘鐢紝閭h繕鑳界敤浠涔堝晩錛熷鍛錛岃繕鑳界敤浠涔堝憿錛熷鏁板瓧鍋氳繍綆楋紝闄や簡鍥涘垯榪愮畻涔嬪錛屼篃灝卞彧鍓╀笅浣嶈繍綆椾簡銆備綅榪愮畻鏄拡瀵逛簩榪涘埗鐨勶紝鎴戜滑涔熷氨浠ヤ簩榪涘埗鍐嶆潵鍒嗘瀽涓涓嬪墠闈㈢殑涓夋璧扮瓥鐣ュ浜岃繘鍒舵槸涓嶆槸涔熺鐢ㄣ?/span></p> <p style="text-indent: 0.5in; margin: 0in 0in 10pt">5<span style="font-family: 瀹嬩綋">鐨勪簩榪涘埗鏄?/span>101<span style="font-family: 瀹嬩綋">錛?/span>17<span style="font-family: 瀹嬩綋">鐨勪簩榪涘埗</span>10001<span style="font-family: 瀹嬩綋">銆傝繕鏄瘯鐫鎶婅綆楀垎鎴愪笁姝ワ細絎竴姝ュ悇浣嶇浉鍔犱絾涓嶈榪涗綅錛屽緱鍒扮殑緇撴灉鏄?/span>10100<span style="font-family: 瀹嬩綋">錛堟渶鍚庝竴浣嶄袱涓暟閮芥槸</span>1<span style="font-family: 瀹嬩綋">錛岀浉鍔犵殑緇撴灉鏄簩榪涘埗鐨?/span>10<span style="font-family: 瀹嬩綋">銆傝繖涓姝ヤ笉璁¤繘浣嶏紝鍥犳緇撴灉浠嶇劧鏄?/span>0<span style="font-family: 瀹嬩綋">錛夛紱絎簩姝ヨ涓嬭繘浣嶃傚湪榪欎釜渚嬪瓙涓彧鍦ㄦ渶鍚庝竴浣嶇浉鍔犳椂浜х敓涓涓繘浣嶏紝緇撴灉鏄簩榪涘埗鐨?/span>10<span style="font-family: 瀹嬩綋">錛涚涓夋鎶婂墠涓ゆ鐨勭粨鏋滅浉鍔狅紝寰楀埌鐨勭粨鏋滄槸</span>10110<span style="font-family: 瀹嬩綋">錛屾濂芥槸</span>22<span style="font-family: 瀹嬩綋">銆傜敱姝ゅ彲瑙佷笁姝ヨ蛋鐨勭瓥鐣ュ浜岃繘鍒朵篃鏄鐢ㄧ殑銆?/span></p> <p style="text-indent: 0.5in; margin: 0in 0in 10pt"><span style="font-family: 瀹嬩綋">鎺ヤ笅鏉ユ垜浠瘯鐫鎶婁簩榪涘埗涓婄殑鍔犳硶鐢ㄤ綅榪愮畻鏉ユ浛浠c傜涓姝ヤ笉鑰冭檻榪涗綅錛屽姣忎竴浣嶇浉鍔犮?/span>0<span style="font-family: 瀹嬩綋">鍔?/span>0<span style="font-family: 瀹嬩綋">涓?/span> 1<span style="font-family: 瀹嬩綋">鍔?/span>1<span style="font-family: 瀹嬩綋">鐨勭粨鏋滈兘</span>0<span style="font-family: 瀹嬩綋">錛?/span>0<span style="font-family: 瀹嬩綋">鍔?/span>1<span style="font-family: 瀹嬩綋">涓?/span>1<span style="font-family: 瀹嬩綋">鍔?/span>0<span style="font-family: 瀹嬩綋">鐨勭粨鏋滈兘鏄?/span>1<span style="font-family: 瀹嬩綋">銆傛垜浠彲浠ユ敞鎰忓埌錛岃繖鍜屽紓鎴栫殑緇撴灉鏄竴鏍風殑銆傚寮傛垨鑰岃█錛?/span>0<span style="font-family: 瀹嬩綋">鍜?/span>0<span style="font-family: 瀹嬩綋">銆?/span>1<span style="font-family: 瀹嬩綋">鍜?/span>1<span style="font-family: 瀹嬩綋">寮傛垨鐨勭粨鏋滄槸</span>0<span style="font-family: 瀹嬩綋">錛岃?/span>0<span style="font-family: 瀹嬩綋">鍜?/span>1<span style="font-family: 瀹嬩綋">銆?/span>1<span style="font-family: 瀹嬩綋">鍜?/span>0<span style="font-family: 瀹嬩綋">鐨勫紓鎴栫粨鏋滄槸</span>1<span style="font-family: 瀹嬩綋">銆傛帴鐫鑰冭檻絎簩姝ヨ繘浣嶏紝瀵?/span>0<span style="font-family: 瀹嬩綋">鍔?/span>0<span style="font-family: 瀹嬩綋">銆?/span>0<span style="font-family: 瀹嬩綋">鍔?/span>1<span style="font-family: 瀹嬩綋">銆?/span>1<span style="font-family: 瀹嬩綋">鍔?/span>0<span style="font-family: 瀹嬩綋">鑰岃█錛岄兘涓嶄細浜х敓榪涗綅錛屽彧鏈?/span>1<span style="font-family: 瀹嬩綋">鍔?/span>1<span style="font-family: 瀹嬩綋">鏃訛紝浼氬悜鍓嶄駭鐢熶竴涓繘浣嶃傛鏃舵垜浠彲浠ユ兂璞℃垚鏄袱涓暟鍏堝仛浣嶄笌榪愮畻錛岀劧鍚庡啀鍚戝乏縐誨姩涓浣嶃傚彧鏈変袱涓暟閮芥槸</span>1<span style="font-family: 瀹嬩綋">鐨勬椂鍊欙紝浣嶄笌寰楀埌鐨勭粨鏋滄槸</span>1<span style="font-family: 瀹嬩綋">錛屽叾浣欓兘鏄?/span>0<span style="font-family: 瀹嬩綋">銆傜涓夋鎶婂墠涓や釜姝ラ鐨勭粨鏋滅浉鍔犮傚鏋滄垜浠畾涔変竴涓嚱鏁?/span>AddWithoutArithmetic<span style="font-family: 瀹嬩綋">錛岀涓夋灝辯浉褰撲簬杈撳叆鍓嶄袱姝ラ鐨勭粨鏋滄潵閫掑綊璋冪敤鑷繁銆?/p> <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#include</span><span style="color: #000000"><</span><span style="color: #000000">stdio.h</span><span style="color: #000000">></span><span style="color: #000000"><br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000"><br />tricky_add(</span><span style="color: #0000ff">int</span><span style="color: #000000"> arg1, </span><span style="color: #0000ff">int</span><span style="color: #000000"> arg2)<br />{<br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> a, b;<br />    a </span><span style="color: #000000">=</span><span style="color: #000000"> arg1 </span><span style="color: #000000">^</span><span style="color: #000000"> arg2; </span><span style="color: #008000">/*</span><span style="color: #008000"> this is the result of arg1+arg2 without carry </span><span style="color: #008000">*/</span><span style="color: #000000"><br />    b </span><span style="color: #000000">=</span><span style="color: #000000"> arg1 </span><span style="color: #000000">&</span><span style="color: #000000"> arg2;<br />    b </span><span style="color: #000000"><<=</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">;<br /><br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(b </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">)<br />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> a;<br />    </span><span style="color: #0000ff">else</span><span style="color: #000000"><br />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> tricky_add(a, b);<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000"><br />main(</span><span style="color: #0000ff">int</span><span style="color: #000000"> argc, </span><span style="color: #0000ff">char</span><span style="color: #000000"> </span><span style="color: #000000">**</span><span style="color: #000000">argv)<br />{<br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> x, y;<br />    </span><span style="color: #0000ff">while</span><span style="color: #000000">(scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%d %d</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">&</span><span style="color: #000000">x, </span><span style="color: #000000">&</span><span style="color: #000000">y) </span><span style="color: #000000">!=</span><span style="color: #000000"> EOF) {<br />        printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">, tricky_add(x, y));<br />    }<br /><br />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div> <p style="text-indent: 0.5in; margin: 0in 0in 10pt"></span></p><br /><br /></div><img src ="http://www.shnenglu.com/Joe/aggbug/148874.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/Joe/" target="_blank">simplyzhao</a> 2011-06-17 17:30 <a href="http://www.shnenglu.com/Joe/archive/2011/06/17/148874.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍜屼負n榪炵畫姝f暟搴忓垪http://www.shnenglu.com/Joe/archive/2011/06/16/148804.htmlsimplyzhaosimplyzhaoThu, 16 Jun 2011 11:33:00 GMThttp://www.shnenglu.com/Joe/archive/2011/06/16/148804.htmlhttp://www.shnenglu.com/Joe/comments/148804.htmlhttp://www.shnenglu.com/Joe/archive/2011/06/16/148804.html#Feedback0http://www.shnenglu.com/Joe/comments/commentRss/148804.htmlhttp://www.shnenglu.com/Joe/services/trackbacks/148804.html棰樼洰鏉ユ簮:
http://zhedahht.blog.163.com/blog/static/25411174200732711051101/

棰樼洰錛氳緭鍏ヤ竴涓鏁?/span>n錛岃緭鍑烘墍鏈夊拰涓?/span>n榪炵畫姝f暟搴忓垪銆?/span>

渚嬪杈撳叆15錛岀敱浜?/span>1+2+3+4+5=4+5+6=7+8=15錛屾墍浠ヨ緭鍑?/span>3涓繛緇簭鍒?/span>1-5銆?/span>4-6鍜?/span>7-8銆?/span>

鍒嗘瀽錛氳繖鏄綉鏄撶殑涓閬撻潰璇曢銆?/span>

榪欓亾棰樺拰鏈潰璇曢緋誨垪鐨勭10棰?/span>鏈変簺綾諱技銆傛垜浠敤涓や釜鏁?/span>small鍜?/span>big鍒嗗埆琛ㄧず搴忓垪鐨勬渶灝忓煎拰鏈澶у箋傞鍏堟妸small鍒濆鍖栦負1錛?/span>big鍒濆鍖栦負2銆傚鏋滀粠small鍒?/span>big鐨勫簭鍒楃殑鍜屽ぇ浜?/span>n鐨勮瘽錛屾垜浠悜鍙崇Щ鍔?/span>small錛岀浉褰撲簬浠庡簭鍒椾腑鍘繪帀杈冨皬鐨勬暟瀛椼傚鏋滀粠small鍒?/span>big鐨勫簭鍒楃殑鍜屽皬浜?/span>n鐨勮瘽錛屾垜浠悜鍙崇Щ鍔?/span>big錛岀浉褰撲簬鍚戝簭鍒椾腑娣誨姞big鐨勪笅涓涓暟瀛椼備竴鐩村埌small絳変簬(1+n)/2錛屽洜涓哄簭鍒楄嚦灝戣鏈変袱涓暟瀛椼?/span>

鍩轟簬榪欎釜鎬濊礬錛屾垜浠彲浠ュ啓鍑哄涓嬩唬鐮侊細

void PrintContinuousSequence(int small, int big);

/////////////////////////////////////////////////////////////////////////
// Find continuous sequence, whose sum is n
/////////////////////////////////////////////////////////////////////////
void FindContinuousSequence(int n)
{
      if(n < 3)
            return;

      int small = 1; 
      int big = 2;
      int middle = (1 + n) / 2;
      int sum = small + big;

      while(small < middle)
      {
            // we are lucky and find the sequence
            if(sum == n)
                  PrintContinuousSequence(small, big);

            // if the current sum is greater than n, 
            // move small forward
            while(sum > n)
            {
                  sum -= small;
                  small ++;

                  // we are lucky and find the sequence
                  if(sum == n)
                        PrintContinuousSequence(small, big);
            }

            // move big forward
            big ++;
            sum += big;
      }
}

/////////////////////////////////////////////////////////////////////////
// Print continuous sequence between small and big
/////////////////////////////////////////////////////////////////////////
void PrintContinuousSequence(int small, int big)
{
      for(int i = small; i <= big; ++ i)
            printf("%d ", i);

      printf("\n");
}





simplyzhao 2011-06-16 19:33 鍙戣〃璇勮
]]>
璺沖彴闃墮棶棰?/title><link>http://www.shnenglu.com/Joe/archive/2011/06/12/148543.html</link><dc:creator>simplyzhao</dc:creator><author>simplyzhao</author><pubDate>Sun, 12 Jun 2011 10:19:00 GMT</pubDate><guid>http://www.shnenglu.com/Joe/archive/2011/06/12/148543.html</guid><wfw:comment>http://www.shnenglu.com/Joe/comments/148543.html</wfw:comment><comments>http://www.shnenglu.com/Joe/archive/2011/06/12/148543.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/Joe/comments/commentRss/148543.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/Joe/services/trackbacks/148543.html</trackback:ping><description><![CDATA[<div>棰樼洰鏉ユ簮:<br /><a >http://zhedahht.blog.163.com/blog/static/25411174200731844235261/</a> <p><span style="font-family: SimSun">棰樼洰錛氫竴涓彴闃舵誨叡鏈?/span>n<span style="font-family: SimSun">綰э紝濡傛灉涓嬈″彲浠ヨ煩</span>1<span style="font-family: SimSun">綰э紝涔熷彲浠ヨ煩</span>2<span style="font-family: SimSun">綰с傛眰鎬誨叡鏈夊灝戞昏煩娉曪紝騫跺垎鏋愮畻娉曠殑鏃墮棿澶嶆潅搴︺?/span></p> <p><span style="font-family: SimSun">鍒嗘瀽錛氳繖閬撻鏈榪戠粡甯稿嚭鐜幫紝鍖呮嫭</span>MicroStrategy<span style="font-family: SimSun">絳夋瘮杈冮噸瑙嗙畻娉曠殑鍏徃閮芥浘鍏堝悗閫夌敤榪囦釜榪欓亾棰樹綔涓洪潰璇曢鎴栬呯瑪璇曢銆?/span></p> <p><span style="font-family: SimSun">棣栧厛鎴戜滑鑰冭檻鏈綆鍗曠殑鎯呭喌銆傚鏋滃彧鏈?/span>1<span style="font-family: SimSun">綰у彴闃訛紝閭f樉鐒跺彧鏈変竴縐嶈煩娉曘傚鏋滄湁</span>2<span style="font-family: SimSun">綰у彴闃訛紝閭e氨鏈変袱縐嶈煩鐨勬柟娉曚簡錛氫竴縐嶆槸鍒嗕袱嬈¤煩錛屾瘡嬈¤煩</span>1<span style="font-family: SimSun">綰э紱鍙﹀涓縐嶅氨鏄竴嬈¤煩</span>2<span style="font-family: SimSun">綰с?/span></p> <p><span style="font-family: SimSun">鐜板湪鎴戜滑鍐嶆潵璁ㄨ涓鑸儏鍐點傛垜浠妸</span>n<span style="font-family: SimSun">綰у彴闃舵椂鐨勮煩娉曠湅鎴愭槸</span>n<span style="font-family: SimSun">鐨勫嚱鏁幫紝璁頒負</span>f(n)<span style="font-family: SimSun">銆傚綋</span>n>2<span style="font-family: SimSun">鏃訛紝絎竴嬈¤煩鐨勬椂鍊欏氨鏈変袱縐嶄笉鍚岀殑閫夋嫨錛氫竴鏄涓嬈″彧璺?/span>1<span style="font-family: SimSun">綰э紝姝ゆ椂璺蟲硶鏁扮洰絳変簬鍚庨潰鍓╀笅鐨?/span>n-1<span style="font-family: SimSun">綰у彴闃剁殑璺蟲硶鏁扮洰錛屽嵆涓?/span>f(n-1)<span style="font-family: SimSun">錛涘彟澶栦竴縐嶉夋嫨鏄涓嬈¤煩</span>2<span style="font-family: SimSun">綰э紝姝ゆ椂璺蟲硶鏁扮洰絳変簬鍚庨潰鍓╀笅鐨?/span>n-2<span style="font-family: SimSun">綰у彴闃剁殑璺蟲硶鏁扮洰錛屽嵆涓?/span>f(n-2)<span style="font-family: SimSun">銆傚洜姝?/span>n<span style="font-family: SimSun">綰у彴闃舵椂鐨勪笉鍚岃煩娉曠殑鎬繪暟</span>f(n)=f(n-1)+(f-2)<span style="font-family: SimSun">銆?/span></p> <p><span style="font-family: SimSun">鎴戜滑鎶婁笂闈㈢殑鍒嗘瀽鐢ㄤ竴涓叕寮忔葷粨濡備笅錛?/span></p> <p>        /  1                          n=1<br />f(n)=      2                          n=2<br />        \  f(n-1)+(f-2)               n>2</p> <p><span style="font-family: SimSun">鍒嗘瀽鍒拌繖閲岋紝鐩鎬俊寰堝浜洪兘鑳界湅鍑鴻繖灝辨槸鎴戜滑鐔熸倝鐨?/span>Fibonacci<span style="font-family: SimSun">搴忓垪銆?/span></p><br /><br /></div><img src ="http://www.shnenglu.com/Joe/aggbug/148543.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/Joe/" target="_blank">simplyzhao</a> 2011-06-12 18:19 <a href="http://www.shnenglu.com/Joe/archive/2011/06/12/148543.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍙嶈漿閾捐〃 寰幆涓庨掑綊http://www.shnenglu.com/Joe/archive/2011/06/12/148533.htmlsimplyzhaosimplyzhaoSun, 12 Jun 2011 08:15:00 GMThttp://www.shnenglu.com/Joe/archive/2011/06/12/148533.htmlhttp://www.shnenglu.com/Joe/comments/148533.htmlhttp://www.shnenglu.com/Joe/archive/2011/06/12/148533.html#Feedback0http://www.shnenglu.com/Joe/comments/commentRss/148533.htmlhttp://www.shnenglu.com/Joe/services/trackbacks/148533.htmlhttp://zhedahht.blog.163.com/blog/static/2541117420073471124487/

#include<stdio.h>
#include
<stdlib.h>
#include
<string.h>

struct Node {
    
char value;
    
struct Node *next;
};

struct Node *
list_reverse(
struct Node *head)
{
    
struct Node *tmp, *cur, *pre = NULL;
    cur 
= head;
    
while(cur) {
        tmp 
= cur->next;
        cur
->next = pre;
        pre 
= cur;
        cur 
= tmp;
    }
    
return pre;
}

struct Node *
list_reverse_recursive(
struct Node *head)
{
    
struct Node *rv;
    
if(head && head->next) {
        rv 
= list_reverse_recursive(head->next);
        head
->next->next = head;
        head
->next = NULL;
        
return rv;
    } 
else 
        
return head;
}

void
test_print(
struct Node *head)
{
    
while(head) {
        printf(
"%c\t", head->value);
        head 
= head->next;
    }
    printf(
"\n");
}

int
main(
int argc, char **argv)
{
    
struct Node d = {'d', NULL};
    
struct Node c = {'c'&d};
    
struct Node b = {'b'&c};
    
struct Node a = {'a'&b};

    test_print(
&a);

    
struct Node *rev_first = list_reverse(&a);

    test_print(rev_first);

    
struct Node *rev_second = list_reverse_recursive(rev_first);

    test_print(rev_second);

    
return 0;
}




simplyzhao 2011-06-12 16:15 鍙戣〃璇勮
]]>
鎶婂瓧絎︿覆杞崲鎴愭暣鏁?/title><link>http://www.shnenglu.com/Joe/archive/2011/06/10/148457.html</link><dc:creator>simplyzhao</dc:creator><author>simplyzhao</author><pubDate>Fri, 10 Jun 2011 11:46:00 GMT</pubDate><guid>http://www.shnenglu.com/Joe/archive/2011/06/10/148457.html</guid><wfw:comment>http://www.shnenglu.com/Joe/comments/148457.html</wfw:comment><comments>http://www.shnenglu.com/Joe/archive/2011/06/10/148457.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/Joe/comments/commentRss/148457.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/Joe/services/trackbacks/148457.html</trackback:ping><description><![CDATA[<div>棰樼洰鏉ユ簮:<br /><a >http://blog.163.com/prevBlogPerma.do?host=zhedahht&srl=25411174200731139971&mode=prev<br /><br /></a> <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#include</span><span style="color: #000000"><</span><span style="color: #000000">stdio.h</span><span style="color: #000000">></span><span style="color: #000000"><br />#include</span><span style="color: #000000"><</span><span style="color: #000000">stdlib.h</span><span style="color: #000000">></span><span style="color: #000000"><br /><br />#include</span><span style="color: #000000"><</span><span style="color: #0000ff">string</span><span style="color: #000000">.h</span><span style="color: #000000">></span><span style="color: #000000"><br />#include</span><span style="color: #000000"><</span><span style="color: #000000">limits.h</span><span style="color: #000000">></span><span style="color: #000000"><br /></span><span style="color: #008000">/*</span><span style="color: #008000"><br /> * #define INT_MAX 2147483647 銆銆<br /> * #define INT_MIN (-INT_MAX-1) <br /> </span><span style="color: #008000">*/</span><span style="color: #000000"><br /><br /></span><span style="color: #0000ff">enum</span><span style="color: #000000"> Status {<br />    Success,<br />    Fail<br />};<br /></span><span style="color: #0000ff">enum</span><span style="color: #000000"> Status ret;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000"> negative;<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000"><br />Str2Int(</span><span style="color: #0000ff">const</span><span style="color: #000000"> </span><span style="color: #0000ff">char</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000">input)<br />{<br />    </span><span style="color: #0000ff">long</span><span style="color: #000000"> </span><span style="color: #0000ff">long</span><span style="color: #000000"> num </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br />    negative </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br />    ret </span><span style="color: #000000">=</span><span style="color: #000000"> Fail;<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(input </span><span style="color: #000000">==</span><span style="color: #000000"> NULL)<br />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> num;<br /><br />    </span><span style="color: #0000ff">const</span><span style="color: #000000"> </span><span style="color: #0000ff">char</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000">ptr </span><span style="color: #000000">=</span><span style="color: #000000"> input;<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">ptr</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">+</span><span style="color: #000000">'</span><span style="color: #000000"> </span><span style="color: #000000">||</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000">ptr</span><span style="color: #000000">==</span><span style="color: #000000">'</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">) {<br />        </span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">ptr </span><span style="color: #000000">==</span><span style="color: #000000"> </span><span style="color: #000000">'</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">)<br />            negative </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">;<br />        </span><span style="color: #000000">++</span><span style="color: #000000">ptr;<br />    }<br />    </span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">ptr) {<br />        </span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">(</span><span style="color: #000000">*</span><span style="color: #000000">ptr</span><span style="color: #000000">>=</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000"> </span><span style="color: #000000">&&</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000">ptr</span><span style="color: #000000"><=</span><span style="color: #000000">'</span><span style="color: #000000">9</span><span style="color: #000000">'</span><span style="color: #000000">)) <br />            </span><span style="color: #0000ff">return</span><span style="color: #000000"> num;<br /><br />        </span><span style="color: #0000ff">if</span><span style="color: #000000">((</span><span style="color: #000000">!</span><span style="color: #000000">negative </span><span style="color: #000000">&&</span><span style="color: #000000"> num</span><span style="color: #000000">></span><span style="color: #000000">INT_MAX) </span><span style="color: #000000">||</span><span style="color: #000000"> (negative </span><span style="color: #000000">&&</span><span style="color: #000000"> (</span><span style="color: #000000">-</span><span style="color: #000000">num)</span><span style="color: #000000"><</span><span style="color: #000000">INT_MIN)) <br />            </span><span style="color: #0000ff">return</span><span style="color: #000000"> num;<br /><br />        num </span><span style="color: #000000">=</span><span style="color: #000000"> num</span><span style="color: #000000">*</span><span style="color: #000000">10</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> (</span><span style="color: #000000">*</span><span style="color: #000000">ptr</span><span style="color: #000000">-</span><span style="color: #000000">'</span><span style="color: #000000">0</span><span style="color: #000000">'</span><span style="color: #000000">);<br />        </span><span style="color: #000000">++</span><span style="color: #000000">ptr;<br />    }<br />    ret </span><span style="color: #000000">=</span><span style="color: #000000"> Success;<br />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> num;<br />}<br /><br /></span><span style="color: #0000ff">#define</span><span style="color: #000000"> MAX_LEN 101</span><span style="color: #000000"><br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000"><br />main(</span><span style="color: #0000ff">int</span><span style="color: #000000"> argc, </span><span style="color: #0000ff">char</span><span style="color: #000000"> </span><span style="color: #000000">**</span><span style="color: #000000">argv)<br />{<br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> result;<br />    </span><span style="color: #0000ff">char</span><span style="color: #000000"> value[MAX_LEN];<br />    </span><span style="color: #0000ff">while</span><span style="color: #000000">(scanf(</span><span style="color: #000000">"</span><span style="color: #000000">%s</span><span style="color: #000000">"</span><span style="color: #000000">, value) </span><span style="color: #000000">!=</span><span style="color: #000000"> EOF) {<br />        result </span><span style="color: #000000">=</span><span style="color: #000000"> Str2Int(value);<br />        </span><span style="color: #0000ff">if</span><span style="color: #000000">(ret </span><span style="color: #000000">==</span><span style="color: #000000"> Success)<br />            printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\n</span><span style="color: #000000">"</span><span style="color: #000000">, negative </span><span style="color: #000000">?</span><span style="color: #000000"> (</span><span style="color: #000000">-</span><span style="color: #000000">result) : result);<br />        </span><span style="color: #0000ff">else</span><span style="color: #000000"><br />            printf(</span><span style="color: #000000">"</span><span style="color: #000000">Invalid\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br />    }<br /><br />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br />}<br /></span></div><br /><br /></div><img src ="http://www.shnenglu.com/Joe/aggbug/148457.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/Joe/" target="_blank">simplyzhao</a> 2011-06-10 19:46 <a href="http://www.shnenglu.com/Joe/archive/2011/06/10/148457.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>甯﹂殢鏈烘寚閽堢殑閾捐〃澶嶅埗http://www.shnenglu.com/Joe/archive/2011/06/09/148328.htmlsimplyzhaosimplyzhaoThu, 09 Jun 2011 03:35:00 GMThttp://www.shnenglu.com/Joe/archive/2011/06/09/148328.htmlhttp://www.shnenglu.com/Joe/comments/148328.htmlhttp://www.shnenglu.com/Joe/archive/2011/06/09/148328.html#Feedback0http://www.shnenglu.com/Joe/comments/commentRss/148328.htmlhttp://www.shnenglu.com/Joe/services/trackbacks/148328.html棰樼洰鏉ユ簮錛?br />http://zhedahht.blog.163.com/blog/static/254111742010819104710337/

棰樼洰錛氭湁涓涓鏉傞摼琛紝鍏剁粨鐐歸櫎浜嗘湁涓涓?font face="Calibri">m_pNext鎸囬拡鎸囧悜涓嬩竴涓粨鐐瑰錛岃繕鏈変竴涓?/span>m_pSibling鎸囧悜閾捐〃涓殑浠諱竴緇撶偣鎴栬?/span>NULL銆傚叾緇撶偣鐨?/span>C++瀹氫箟濡備笅錛?/span>

                struct ComplexNode

{

    int m_nValue;

    ComplexNode* m_pNext;

    ComplexNode* m_pSibling;

};


浠g爜錛?
#include<stdio.h>
#include
<stdlib.h>
#include
<string.h>

struct Node {
    
char value;

    
struct Node *next;
    
struct Node *random;
};

void test_print(struct Node *);

struct Node *
list_copy_with_random_pointer(
struct Node *head)
{
    
struct Node *tmp, *ptr, *ret;

    ptr 
= head;
    
while(ptr != NULL) {
        tmp 
= (struct Node *)malloc(sizeof(struct Node));
        tmp
->value = (ptr->value)-32/* from lowercase to uppercase, just for testing */
        tmp
->next = ptr->next;
        tmp
->random = NULL;

        ptr
->next = tmp;

        ptr 
= ptr->next->next;
    }

    ptr 
= head;
    
while(ptr != NULL) {
        ptr
->next->random = ptr->random==NULL ? NULL : ptr->random->next;

        ptr 
= ptr->next->next;
    }

    ptr 
= head;
    ret 
= (head==NULL ? NULL : (head->next));
    
while(ptr != NULL) {
        tmp 
= ptr->next;
        ptr
->next = ptr->next->next;
        tmp
->next = ptr->next==NULL ? NULL : ptr->next->next;

        ptr 
= ptr->next;
    }

    
return ret;
}

void
test_print(
struct Node *head)
{
    
while(head != NULL) {
        printf(
"%c: [%c, %c]\n", head->value, head->next==NULL?'-':head->next->value, head->random==NULL?'-':head->random->value);

        head 
= head->next;
    }
}

int
main(
int argc, char **argv)
{
    
struct Node d = {'d', NULL, NULL};
    
struct Node c = {'c'&d, NULL};
    
struct Node b = {'b'&c, NULL};
    
struct Node a = {'a'&b, NULL};
    a.random 
= &c;
    d.random 
= &b;

    test_print(
&a);

    
struct Node *copy = list_copy_with_random_pointer(&a);

    printf(
"\n\n");
    test_print(
&a);
    printf(
"\n\n");
    test_print(copy);

    
return 0;
}



]]>
姹備簩鍏冩煡鎵炬爲鐨勯暅鍍?/title><link>http://www.shnenglu.com/Joe/archive/2011/06/01/147890.html</link><dc:creator>simplyzhao</dc:creator><author>simplyzhao</author><pubDate>Wed, 01 Jun 2011 11:58:00 GMT</pubDate><guid>http://www.shnenglu.com/Joe/archive/2011/06/01/147890.html</guid><wfw:comment>http://www.shnenglu.com/Joe/comments/147890.html</wfw:comment><comments>http://www.shnenglu.com/Joe/archive/2011/06/01/147890.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/Joe/comments/commentRss/147890.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/Joe/services/trackbacks/147890.html</trackback:ping><description><![CDATA[<div>棰樼洰鏉ユ簮錛?<a >http://blog.163.com/prevBlogPerma.do?host=zhedahht&srl=2541117420072159363370&mode=prev</a><br /><br /><span style="font-family: SimSun">棰樼洰錛氳緭鍏ヤ竴棰椾簩鍏冩煡鎵炬爲錛屽皢璇ユ爲杞崲涓哄畠鐨勯暅鍍忥紝鍗沖湪杞崲鍚庣殑浜屽厓鏌ユ壘鏍戜腑錛屽乏瀛愭爲鐨勭粨鐐歸兘澶т簬鍙沖瓙鏍戠殑緇撶偣銆傜敤閫掑綊鍜屽驚鐜袱縐嶆柟娉曞畬鎴愭爲鐨勯暅鍍忚漿鎹€?/span> <p><span style="font-family: SimSun">渚嬪杈撳叆錛?/span></p> <p><span style="mso-spacerun: yes">     </span>8<br /><span style="mso-spacerun: yes">    </span>/<span style="mso-spacerun: yes">  </span>\<br /><span style="mso-spacerun: yes">  </span>6<span style="mso-spacerun: yes">      </span>10<br /> /\<span style="mso-spacerun: yes">       </span>/\<br />5<span style="mso-spacerun: yes">  </span>7<span style="mso-spacerun: yes">    </span>9<span style="mso-spacerun: yes">   </span>11</p> <p><span style="font-family: SimSun">杈撳嚭錛?/span></p> <p><span style="mso-spacerun: yes">      </span>8<br /><span style="mso-spacerun: yes">    </span>/<span style="mso-spacerun: yes">  </span>\<br /><span style="mso-spacerun: yes">  </span>10 <span style="mso-spacerun: yes">   </span>6<br /> /\ <span style="mso-spacerun: yes"> </span><span style="mso-spacerun: yes">  </span><span style="mso-spacerun: yes">  </span>/\<br />11<span style="mso-spacerun: yes"> </span><span style="mso-spacerun: yes"> </span>9  7<span style="mso-spacerun: yes">  </span>5</p> <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#include</span><span style="color: #000000"><</span><span style="color: #000000">stdio.h</span><span style="color: #000000">></span><span style="color: #000000"><br />#include</span><span style="color: #000000"><</span><span style="color: #000000">stdlib.h</span><span style="color: #000000">></span><span style="color: #000000"><br />#include</span><span style="color: #000000"><</span><span style="color: #0000ff">string</span><span style="color: #000000">.h</span><span style="color: #000000">></span><span style="color: #000000"><br /><br /></span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node {<br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> value;<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">left;<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">right;<br />};<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000"><br />bst_preorder(</span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">root)<br />{<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(root </span><span style="color: #000000">==</span><span style="color: #000000"> NULL)<br />        </span><span style="color: #0000ff">return</span><span style="color: #000000">;<br /><br />    printf(</span><span style="color: #000000">"</span><span style="color: #000000">%d\t</span><span style="color: #000000">"</span><span style="color: #000000">, root</span><span style="color: #000000">-></span><span style="color: #000000">value);<br />    bst_preorder(root</span><span style="color: #000000">-></span><span style="color: #000000">left);<br />    bst_preorder(root</span><span style="color: #000000">-></span><span style="color: #000000">right);<br />}<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000"><br />bst_mirror_recursive(</span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">root) </span><span style="color: #008000">/*</span><span style="color: #008000"> easy </span><span style="color: #008000">*/</span><span style="color: #000000"><br />{<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(root </span><span style="color: #000000">==</span><span style="color: #000000"> NULL)<br />        </span><span style="color: #0000ff">return</span><span style="color: #000000">;<br /><br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">ptr </span><span style="color: #000000">=</span><span style="color: #000000"> root</span><span style="color: #000000">-></span><span style="color: #000000">left;<br />    root</span><span style="color: #000000">-></span><span style="color: #000000">left </span><span style="color: #000000">=</span><span style="color: #000000"> root</span><span style="color: #000000">-></span><span style="color: #000000">right;<br />    root</span><span style="color: #000000">-></span><span style="color: #000000">right </span><span style="color: #000000">=</span><span style="color: #000000"> ptr;<br /><br />    bst_mirror_recursive(root</span><span style="color: #000000">-></span><span style="color: #000000">left);<br />    bst_mirror_recursive(root</span><span style="color: #000000">-></span><span style="color: #000000">right);<br />}<br /><br /></span><span style="color: #008000">/*</span><span style="color: #008000"> STACK : naive </span><span style="color: #008000">*/</span><span style="color: #000000"><br /></span><span style="color: #0000ff">#define</span><span style="color: #000000"> STACK_SIZE 101</span><span style="color: #000000"><br /></span><span style="color: #0000ff">struct</span><span style="color: #000000"> Stack {<br />    </span><span style="color: #0000ff">void</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000">data[STACK_SIZE];<br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> top;<br />};<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000"><br />stack_pop(</span><span style="color: #0000ff">struct</span><span style="color: #000000"> Stack </span><span style="color: #000000">*</span><span style="color: #000000">stack)<br />{<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">((stack</span><span style="color: #000000">-></span><span style="color: #000000">top) </span><span style="color: #000000">>=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">)<br />        </span><span style="color: #000000">--</span><span style="color: #000000">(stack</span><span style="color: #000000">-></span><span style="color: #000000">top);<br />}<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000"><br />stack_top(</span><span style="color: #0000ff">struct</span><span style="color: #000000"> Stack </span><span style="color: #000000">*</span><span style="color: #000000">stack)<br />{<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">((stack</span><span style="color: #000000">-></span><span style="color: #000000">top) </span><span style="color: #000000">>=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">)<br />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> stack</span><span style="color: #000000">-></span><span style="color: #000000">data[stack</span><span style="color: #000000">-></span><span style="color: #000000">top];<br /><br />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> NULL;<br />}<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000"><br />stack_push(</span><span style="color: #0000ff">struct</span><span style="color: #000000"> Stack </span><span style="color: #000000">*</span><span style="color: #000000">stack, </span><span style="color: #0000ff">void</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000">entity)<br />{<br />    stack</span><span style="color: #000000">-></span><span style="color: #000000">data[</span><span style="color: #000000">++</span><span style="color: #000000">(stack</span><span style="color: #000000">-></span><span style="color: #000000">top)] </span><span style="color: #000000">=</span><span style="color: #000000"> entity;<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000"><br />stack_isempty(</span><span style="color: #0000ff">struct</span><span style="color: #000000"> Stack </span><span style="color: #000000">*</span><span style="color: #000000">stack)<br />{<br />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> (stack</span><span style="color: #000000">-></span><span style="color: #000000">top) </span><span style="color: #000000"><</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br />}<br /><br /></span><span style="color: #0000ff">void</span><span style="color: #000000"><br />bst_mirror_nonrecursive(</span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">root, </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Stack </span><span style="color: #000000">*</span><span style="color: #000000">aux_stack) </span><span style="color: #008000">/*</span><span style="color: #008000"> stack used : good method </span><span style="color: #008000">*/</span><span style="color: #000000"><br />{<br />    stack_push(aux_stack, root);<br />    </span><span style="color: #0000ff">while</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">stack_isempty(aux_stack)) {<br />        </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">node </span><span style="color: #000000">=</span><span style="color: #000000"> (</span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">)stack_top(aux_stack);<br /><br />        </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">ptr </span><span style="color: #000000">=</span><span style="color: #000000"> node</span><span style="color: #000000">-></span><span style="color: #000000">left;<br />        node</span><span style="color: #000000">-></span><span style="color: #000000">left </span><span style="color: #000000">=</span><span style="color: #000000"> node</span><span style="color: #000000">-></span><span style="color: #000000">right;<br />        node</span><span style="color: #000000">-></span><span style="color: #000000">right </span><span style="color: #000000">=</span><span style="color: #000000"> ptr;<br /><br />        stack_pop(aux_stack);<br />        </span><span style="color: #0000ff">if</span><span style="color: #000000">(node</span><span style="color: #000000">-></span><span style="color: #000000">left)<br />            stack_push(aux_stack, node</span><span style="color: #000000">-></span><span style="color: #000000">left);<br />        </span><span style="color: #0000ff">if</span><span style="color: #000000">(node</span><span style="color: #000000">-></span><span style="color: #000000">right)<br />            stack_push(aux_stack, node</span><span style="color: #000000">-></span><span style="color: #000000">right);<br />    }<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000"><br />main(</span><span style="color: #0000ff">int</span><span style="color: #000000"> argc, </span><span style="color: #0000ff">char</span><span style="color: #000000"> </span><span style="color: #000000">**</span><span style="color: #000000">argv)<br />{<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node a </span><span style="color: #000000">=</span><span style="color: #000000"> {</span><span style="color: #000000">5</span><span style="color: #000000">, NULL, NULL};<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node b </span><span style="color: #000000">=</span><span style="color: #000000"> {</span><span style="color: #000000">7</span><span style="color: #000000">, NULL, NULL};<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node c </span><span style="color: #000000">=</span><span style="color: #000000"> {</span><span style="color: #000000">9</span><span style="color: #000000">, NULL, NULL};<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node d </span><span style="color: #000000">=</span><span style="color: #000000"> {</span><span style="color: #000000">11</span><span style="color: #000000">, NULL, NULL};<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node e </span><span style="color: #000000">=</span><span style="color: #000000"> {</span><span style="color: #000000">6</span><span style="color: #000000">, </span><span style="color: #000000">&</span><span style="color: #000000">a, </span><span style="color: #000000">&</span><span style="color: #000000">b};<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node f </span><span style="color: #000000">=</span><span style="color: #000000"> {</span><span style="color: #000000">10</span><span style="color: #000000">, </span><span style="color: #000000">&</span><span style="color: #000000">c, </span><span style="color: #000000">&</span><span style="color: #000000">d};<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node g </span><span style="color: #000000">=</span><span style="color: #000000"> {</span><span style="color: #000000">8</span><span style="color: #000000">, </span><span style="color: #000000">&</span><span style="color: #000000">e, </span><span style="color: #000000">&</span><span style="color: #000000">f};<br /><br />    bst_preorder(</span><span style="color: #000000">&</span><span style="color: #000000">g);<br />    printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br />    bst_mirror_recursive(</span><span style="color: #000000">&</span><span style="color: #000000">g);<br />    bst_preorder(</span><span style="color: #000000">&</span><span style="color: #000000">g);<br />    printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><br />    bst_mirror_recursive(</span><span style="color: #000000">&</span><span style="color: #000000">g);<br />    bst_preorder(</span><span style="color: #000000">&</span><span style="color: #000000">g);<br />    printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Stack aux </span><span style="color: #000000">=</span><span style="color: #000000"> {{</span><span style="color: #000000">0</span><span style="color: #000000">}, </span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">};<br />    bst_mirror_nonrecursive(</span><span style="color: #000000">&</span><span style="color: #000000">g, </span><span style="color: #000000">&</span><span style="color: #000000">aux);<br />    bst_preorder(</span><span style="color: #000000">&</span><span style="color: #000000">g);<br />    printf(</span><span style="color: #000000">"</span><span style="color: #000000">\n</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><br />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br />}<br /></span></div> <p> </p><br /><br /><br /></div><img src ="http://www.shnenglu.com/Joe/aggbug/147890.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/Joe/" target="_blank">simplyzhao</a> 2011-06-01 19:58 <a href="http://www.shnenglu.com/Joe/archive/2011/06/01/147890.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>鍒ゆ柇浜屽弶鏍戞槸涓嶆槸騫寵 鐨?/title><link>http://www.shnenglu.com/Joe/archive/2011/05/31/147762.html</link><dc:creator>simplyzhao</dc:creator><author>simplyzhao</author><pubDate>Tue, 31 May 2011 08:58:00 GMT</pubDate><guid>http://www.shnenglu.com/Joe/archive/2011/05/31/147762.html</guid><wfw:comment>http://www.shnenglu.com/Joe/comments/147762.html</wfw:comment><comments>http://www.shnenglu.com/Joe/archive/2011/05/31/147762.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/Joe/comments/commentRss/147762.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/Joe/services/trackbacks/147762.html</trackback:ping><description><![CDATA[<div>棰樼洰鏉ユ簮: <a >http://zhedahht.blog.163.com/blog/static/25411174201142733927831/</a><br /><br /> <p style="text-indent: 0.5in; margin: 0in 0in 10pt"><font size="3"><span style="font-family: 瀹嬩綋; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri" lang="ZH-CN"><span style="line-height: 115%; font-family: 瀹嬩綋; font-size: 11pt; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA" lang="ZH-CN">棰樼洰錛?/span><strong>杈撳叆涓媯典簩鍙夋爲鐨勬牴緇撶偣錛屽垽鏂鏍戞槸涓嶆槸騫寵 浜屽弶鏍戙傚鏋滄煇浜屽弶鏍戜腑浠繪剰緇撶偣鐨勫乏鍙沖瓙鏍戠殑娣卞害鐩稿樊涓嶈秴榪?/strong></span><font face="Calibri"><strong>1</strong></font><span><strong>錛岄偅涔堝畠灝辨槸涓媯靛鉤琛′簩鍙夋爲銆?br /></strong></span><span style="font-family: 瀹嬩綋; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri" lang="ZH-CN"><br /></p> <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">#include</span><span style="color: #000000"><</span><span style="color: #000000">stdio.h</span><span style="color: #000000">></span><span style="color: #000000"><br />#include</span><span style="color: #000000"><</span><span style="color: #000000">stdlib.h</span><span style="color: #000000">></span><span style="color: #000000"><br />#include</span><span style="color: #000000"><</span><span style="color: #0000ff">string</span><span style="color: #000000">.h</span><span style="color: #000000">></span><span style="color: #000000"><br /></span><span style="color: #0000ff">#define</span><span style="color: #000000"> MAX(a, b) ((a)>(b) ? (a) : (b))</span><span style="color: #000000"><br /></span><span style="color: #0000ff">#define</span><span style="color: #000000"> ABS(x) ((x)>=0 ? (x) : ((x)*(-1)))</span><span style="color: #000000"><br /><br /></span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node {<br />    </span><span style="color: #0000ff">void</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000">data;<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">left, </span><span style="color: #000000">*</span><span style="color: #000000">right;<br />};<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000"><br />depth(</span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">root)<br />{<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(root </span><span style="color: #000000">==</span><span style="color: #000000"> NULL)<br />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> ldepth </span><span style="color: #000000">=</span><span style="color: #000000"> depth(root</span><span style="color: #000000">-></span><span style="color: #000000">left);<br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> rdepth </span><span style="color: #000000">=</span><span style="color: #000000"> depth(root</span><span style="color: #000000">-></span><span style="color: #000000">right);<br /><br />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> MAX(ldepth, rdepth) </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">;<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000"><br />btree_isbalanced_naive(</span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">root) </span><span style="color: #008000">/*</span><span style="color: #008000"> return 1 if balanced, or return 0 </span><span style="color: #008000">*/</span><span style="color: #000000"><br />{<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(root </span><span style="color: #000000">==</span><span style="color: #000000"> NULL)<br />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">;<br /><br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> ldepth </span><span style="color: #000000">=</span><span style="color: #000000"> depth(root</span><span style="color: #000000">-></span><span style="color: #000000">left);<br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> rdepth </span><span style="color: #000000">=</span><span style="color: #000000"> depth(root</span><span style="color: #000000">-></span><span style="color: #000000">right);<br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> diff </span><span style="color: #000000">=</span><span style="color: #000000"> ldepth </span><span style="color: #000000">-</span><span style="color: #000000"> rdepth;<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(ABS(diff) </span><span style="color: #000000">></span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">)<br />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><br />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> (btree_isbalanced_naive(root</span><span style="color: #000000">-></span><span style="color: #000000">left) </span><span style="color: #000000">&&</span><span style="color: #000000"> btree_isbalanced_naive(root</span><span style="color: #000000">-></span><span style="color: #000000">right));<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000"><br />btree_isbalanced(</span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node </span><span style="color: #000000">*</span><span style="color: #000000">root, </span><span style="color: #0000ff">int</span><span style="color: #000000"> </span><span style="color: #000000">*</span><span style="color: #000000">depth)<br />{<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(root </span><span style="color: #000000">==</span><span style="color: #000000"> NULL) {<br />        </span><span style="color: #000000">*</span><span style="color: #000000">depth </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">;<br />    }<br /><br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> ldepth, rdepth, diff;<br />    </span><span style="color: #0000ff">if</span><span style="color: #000000">(</span><span style="color: #000000">!</span><span style="color: #000000">btree_isbalanced(root</span><span style="color: #000000">-></span><span style="color: #000000">left, </span><span style="color: #000000">&</span><span style="color: #000000">ldepth) </span><span style="color: #000000">||</span><span style="color: #000000"> </span><span style="color: #000000">!</span><span style="color: #000000">btree_isbalanced(root</span><span style="color: #000000">-></span><span style="color: #000000">right, </span><span style="color: #000000">&</span><span style="color: #000000">rdepth))<br />        </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br /><br />    </span><span style="color: #000000">*</span><span style="color: #000000">depth </span><span style="color: #000000">=</span><span style="color: #000000"> MAX(ldepth, rdepth) </span><span style="color: #000000">+</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000">;<br />    diff </span><span style="color: #000000">=</span><span style="color: #000000"> ldepth </span><span style="color: #000000">-</span><span style="color: #000000"> rdepth;<br />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> (ABS(diff)</span><span style="color: #000000"><=</span><span style="color: #000000">1</span><span style="color: #000000"> </span><span style="color: #000000">?</span><span style="color: #000000"> </span><span style="color: #000000">1</span><span style="color: #000000"> : </span><span style="color: #000000">0</span><span style="color: #000000">);<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000"><br />main(</span><span style="color: #0000ff">int</span><span style="color: #000000"> argc, </span><span style="color: #0000ff">char</span><span style="color: #000000"> </span><span style="color: #000000">**</span><span style="color: #000000">argv)<br />{<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node a </span><span style="color: #000000">=</span><span style="color: #000000"> {NULL, NULL, NULL};<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node b </span><span style="color: #000000">=</span><span style="color: #000000"> {NULL, NULL, NULL};<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node c </span><span style="color: #000000">=</span><span style="color: #000000"> {NULL, NULL ,NULL};<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node d </span><span style="color: #000000">=</span><span style="color: #000000"> {NULL, </span><span style="color: #000000">&</span><span style="color: #000000">b, NULL};<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node e </span><span style="color: #000000">=</span><span style="color: #000000"> {NULL, </span><span style="color: #000000">&</span><span style="color: #000000">a, </span><span style="color: #000000">&</span><span style="color: #000000">d};<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node f </span><span style="color: #000000">=</span><span style="color: #000000"> {NULL, NULL, NULL};<br />    </span><span style="color: #0000ff">struct</span><span style="color: #000000"> Node g </span><span style="color: #000000">=</span><span style="color: #000000"> {NULL, </span><span style="color: #000000">&</span><span style="color: #000000">e, </span><span style="color: #000000">&</span><span style="color: #000000">f};<br /><br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> ret1 </span><span style="color: #000000">=</span><span style="color: #000000"> btree_isbalanced_naive(</span><span style="color: #000000">&</span><span style="color: #000000">g);<br />    printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s\n</span><span style="color: #000000">"</span><span style="color: #000000">, ret1 </span><span style="color: #000000">?</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">YES</span><span style="color: #000000">"</span><span style="color: #000000"> : </span><span style="color: #000000">"</span><span style="color: #000000">NO</span><span style="color: #000000">"</span><span style="color: #000000">);<br /><br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> dpth </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br />    </span><span style="color: #0000ff">int</span><span style="color: #000000"> ret2 </span><span style="color: #000000">=</span><span style="color: #000000"> btree_isbalanced(</span><span style="color: #000000">&</span><span style="color: #000000">g, </span><span style="color: #000000">&</span><span style="color: #000000">dpth);<br />    printf(</span><span style="color: #000000">"</span><span style="color: #000000">%s : %d\n</span><span style="color: #000000">"</span><span style="color: #000000">, ret2 </span><span style="color: #000000">?</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">YES</span><span style="color: #000000">"</span><span style="color: #000000"> : </span><span style="color: #000000">"</span><span style="color: #000000">NO</span><span style="color: #000000">"</span><span style="color: #000000">, dpth);<br />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div> <p style="text-indent: 0.5in; margin: 0in 0in 10pt"></span></font></p><span style="line-height: 115%; font-family: 'Calibri', 'sans-serif'; font-size: 11pt; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA; mso-fareast-font-family: 瀹嬩綋"></span><font size="3"><span style="font-family: 瀹嬩綋; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri" lang="ZH-CN"> <p align="center"> </p></span></font><br /><br /></div><img src ="http://www.shnenglu.com/Joe/aggbug/147762.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/Joe/" target="_blank">simplyzhao</a> 2011-05-31 16:58 <a href="http://www.shnenglu.com/Joe/archive/2011/05/31/147762.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>璁捐鍖呭惈min鍑芥暟鐨勬爤http://www.shnenglu.com/Joe/archive/2011/05/25/147091.htmlsimplyzhaosimplyzhaoWed, 25 May 2011 07:49:00 GMThttp://www.shnenglu.com/Joe/archive/2011/05/25/147091.htmlhttp://www.shnenglu.com/Joe/comments/147091.htmlhttp://www.shnenglu.com/Joe/archive/2011/05/25/147091.html#Feedback0http://www.shnenglu.com/Joe/comments/commentRss/147091.htmlhttp://www.shnenglu.com/Joe/services/trackbacks/147091.html棰樼洰鍑哄: http://zhedahht.blog.163.com/blog/static/25411174200712895228171/

棰樼洰錛氬畾涔夋爤鐨勬暟鎹粨鏋勶紝瑕佹眰娣誨姞涓涓?/span>min鍑芥暟錛岃兘澶熷緱鍒版爤鐨勬渶灝忓厓绱犮傝姹傚嚱鏁?/span>min銆?/span>push浠ュ強pop鐨勬椂闂村鏉傚害閮芥槸O(1)銆?/span>
#include "StackWithMin.h"
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>

const int StackWithMin::MAX_SIZE ;

StackWithMin::StackWithMin() :
    top_index(
-1), min_index(-1)
{
    printf(
"StackWithMin Constructor\n");
}

StackWithMin::
~StackWithMin()
{
    printf(
"StackWithMin Destructor\n");
}

int
StackWithMin::top() 
const
{
    
if(top_index == -1) {
        printf(
"top() failed: Stack Empty\n");
        
return -1;
    }

    
return stack[top_index]; 
}

int
StackWithMin::get_min() 
const
{
    
if(min_index == -1) {
        printf(
"get_min() failed: Stack Empty\n");
        
return -1;
    }

    
return stack[min_index];
}

void
StackWithMin::push(
int value)
{
    
if(top_index == -1) { /* stack empty */
        stack[
++top_index] = value;
        min_index 
= top_index;
        
return;
    }
    stack[
++top_index] = value;
    
if(value < stack[min_index]) {
        index[top_index] 
= min_index;
        min_index 
= top_index;
    }
}

int
StackWithMin::pop()
{
    
if(top_index == -1) {
        printf(
"pop() failed: Stack Empty\n");
        
return -1;
    }
    
int ret = stack[top_index];
    
if(min_index == top_index)
        min_index 
= index[top_index];
    
--top_index;
    
return ret;
}



class StackWithMin
{
    public:
        StackWithMin();
        ~StackWithMin();
        int get_min() const;
        int top() const;
        void push(int value);
        int pop();      
    private:
        static const int MAX_SIZE = 101;
        int top_index, min_index;
        int stack[MAX_SIZE];
        int index[MAX_SIZE];
};











]]>
鎶婁簩鍏冩煡鎵炬爲杞彉鎴愭帓搴忕殑鍙屽悜閾捐〃http://www.shnenglu.com/Joe/archive/2011/05/23/146954.htmlsimplyzhaosimplyzhaoMon, 23 May 2011 01:09:00 GMThttp://www.shnenglu.com/Joe/archive/2011/05/23/146954.htmlhttp://www.shnenglu.com/Joe/comments/146954.htmlhttp://www.shnenglu.com/Joe/archive/2011/05/23/146954.html#Feedback0http://www.shnenglu.com/Joe/comments/commentRss/146954.htmlhttp://www.shnenglu.com/Joe/services/trackbacks/146954.html棰樼洰鍑哄: http://zhedahht.blog.163.com/

棰樼洰錛氳緭鍏ヤ竴媯典簩鍏冩煡鎵炬爲錛屽皢璇ヤ簩鍏冩煡鎵炬爲杞崲鎴愪竴涓帓搴忕殑鍙屽悜閾捐〃銆傝姹備笉鑳藉垱寤轟換浣曟柊鐨勭粨鐐癸紝鍙皟鏁存寚閽堢殑鎸囧悜銆?

銆銆姣斿灝嗕簩鍏冩煡鎵炬爲
   
                                        10
                                          /    \
                                        6       14
                                      /  \     /銆 \
                                   銆4     8  12 銆  16
杞崲鎴愬弻鍚戦摼琛?/span>

4=6=8=10=12=14=16銆?/span>


鎬濊礬錛氶掑綊錛屽湪涓鏃舵壘涓嶅埌閫掑綊鐨勭伒鎰熺殑鏃跺欙紝澶氳冭檻鑰冭檻閫掑綊鐨勫弬鏁幫紝鏈夋椂鏇撮噸瑕佺殑鏄冭檻閫掑綊鐨勮繑鍥炲?br />      姣忓鐞嗕竴涓妭鐐癸紝棣栧厛鑾峰彇宸﹀瓙鏍戝拰鍙沖瓙鏍戞墍榪斿洖鐨勯摼琛紝鐒跺悗鎷兼帴

浠g爜錛?
#include<stdio.h>
#include
<string.h>
#include
<stdlib.h>

/* Problem: Convert a binary search tree into a sorted linkedlist */
/* When it comes to Tree-Structure, recursion is always the most common solution.
   When designing recursion solution, should consider:
       1. the parameters
       2(important). the return object
*/

struct Node {
    
int value;
    
struct Node *left;
    
struct Node *right;
};

struct Node *
BTree2List(
struct Node *root)
{
    
if(root == NULL)
        
return NULL;
    
struct Node *ret = NULL;

    
/* Convert the left tree into a sorted linkedlist */
    
struct Node *l_linkedlist = BTree2List(root->left);
    ret 
= l_linkedlist==NULL ? root : l_linkedlist;

    
/* Convert the right tree into a sorted linkedlist */
    
struct Node *r_linkedlist = BTree2List(root->right);
    
while(l_linkedlist && l_linkedlist->right)
        l_linkedlist 
= l_linkedlist->right;

    
/* Combine */
    
if(l_linkedlist)
        l_linkedlist
->right = root;
    root
->left = l_linkedlist;
    root
->right = r_linkedlist;
    
if(r_linkedlist)
        r_linkedlist
->left = root;
    
    
return ret;
}

int main(int argc, char** argv)
{
    
struct Node a = {4, NULL, NULL};
    
struct Node b = {8, NULL, NULL};
    
struct Node c = {12, NULL, NULL};
    
struct Node d = {16, NULL, NULL};
    
struct Node e = {6, NULL, &b};
    
struct Node f = {14&c, NULL};
    
struct Node g = {10&e, &f};

    
struct Node *ret = BTree2List(&g);
    
while(ret && ret->right) {
        ret 
= ret->right;
    }

    
while(ret) {
        printf(
"%d\n", ret->value);
        ret 
= ret->left;
    }

    
return 0;
}




simplyzhao 2011-05-23 09:09 鍙戣〃璇勮
]]>
亚洲综合精品香蕉久久网| 久久久久久亚洲AV无码专区| 久久综合久久综合久久综合| 国产精品永久久久久久久久久| 久久无码人妻精品一区二区三区| 久久综合九色综合网站| 久久久91精品国产一区二区三区| 亚洲国产精品成人久久蜜臀 | 久久中文字幕人妻丝袜| 99久久精品费精品国产一区二区| 久久九九久精品国产免费直播| 97精品依人久久久大香线蕉97 | 国产69精品久久久久久人妻精品| 99久久er这里只有精品18| 久久久久亚洲精品中文字幕| 国内精品久久久久久99蜜桃| 亚洲欧洲精品成人久久曰影片| 久久精品国产一区| 亚洲中文精品久久久久久不卡| 久久福利片| 国产精品美女久久久| 亚洲精品国产字幕久久不卡 | 香蕉久久一区二区不卡无毒影院 | 日本精品久久久久中文字幕8| 久久99热这里只有精品国产| 久久亚洲国产精品五月天婷| 久久免费高清视频| www性久久久com| 久久久久人妻精品一区| 久久久精品人妻一区二区三区蜜桃| 国内精品久久久久久久亚洲| 久久免费线看线看| 久久r热这里有精品视频| 蜜臀久久99精品久久久久久小说| 精品国产乱码久久久久软件 | 欧美亚洲国产精品久久蜜芽| 国产精品对白刺激久久久| 亚洲精品无码久久久久去q| 影音先锋女人AV鲁色资源网久久 | 久久青青草原国产精品免费| 国产精品一区二区久久精品|