﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-メmarsメ-随笔分类-AL</title><link>http://www.cppblog.com/jxtgddlt/category/17793.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 10 Jan 2012 17:06:30 GMT</lastBuildDate><pubDate>Tue, 10 Jan 2012 17:06:30 GMT</pubDate><ttl>60</ttl><item><title>判断一个数是4的整数次幂</title><link>http://www.cppblog.com/jxtgddlt/archive/2011/12/12/161989.html</link><dc:creator>メmarsメ</dc:creator><author>メmarsメ</author><pubDate>Mon, 12 Dec 2011 14:00:00 GMT</pubDate><guid>http://www.cppblog.com/jxtgddlt/archive/2011/12/12/161989.html</guid><wfw:comment>http://www.cppblog.com/jxtgddlt/comments/161989.html</wfw:comment><comments>http://www.cppblog.com/jxtgddlt/archive/2011/12/12/161989.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jxtgddlt/comments/commentRss/161989.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jxtgddlt/services/trackbacks/161989.html</trackback:ping><description><![CDATA[<div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">bool</span>&nbsp;fn(unsigned&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;x)&nbsp;<br />{&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;(&nbsp;x&nbsp;&amp;&nbsp;(x&nbsp;-&nbsp;1)&nbsp;)&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;<span style="color: #0000FF; ">false</span>;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;x&nbsp;&amp;&nbsp;0x55555555;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">如果前面两句能通过，就已经证明了x是4的整数倍数。这句返回的就是那个数&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">类型是bool&nbsp;则返回值就是真了&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">//</span><span style="color: #008000; ">任何二进制只有一个1的数（二的N次幂）</span><span style="color: #008000; "><br /></span>}</div><img src ="http://www.cppblog.com/jxtgddlt/aggbug/161989.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jxtgddlt/" target="_blank">メmarsメ</a> 2011-12-12 22:00 <a href="http://www.cppblog.com/jxtgddlt/archive/2011/12/12/161989.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>不能使用库函数 不能定义其他的变量 strcpy逆序拷贝</title><link>http://www.cppblog.com/jxtgddlt/archive/2011/11/25/160939.html</link><dc:creator>メmarsメ</dc:creator><author>メmarsメ</author><pubDate>Thu, 24 Nov 2011 18:19:00 GMT</pubDate><guid>http://www.cppblog.com/jxtgddlt/archive/2011/11/25/160939.html</guid><wfw:comment>http://www.cppblog.com/jxtgddlt/comments/160939.html</wfw:comment><comments>http://www.cppblog.com/jxtgddlt/archive/2011/11/25/160939.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jxtgddlt/comments/commentRss/160939.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jxtgddlt/services/trackbacks/160939.html</trackback:ping><description><![CDATA[<div><span style="font-family: simsun; line-height: 23px; background-color: #ffffff; ">写C语言的拷贝函数,要求复制字符串，并且将复制后的字符串逆序 比如from中是1234, 则to中是4321 void strcyp(char * to,const char * from)问题补充： &nbsp;&nbsp;</span><br style="font-family: simsun; line-height: 23px; text-align: left; background-color: #ffffff; " /><span style="font-family: simsun; line-height: 23px; text-align: left; background-color: #ffffff; ">要求： </span><span style="font-family: simsun; line-height: 23px; text-align: left; background-color: #ffffff; color: red; ">不能使用库函数 不能定义其他的变量。<br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><br />#include&nbsp;&lt;stdio.h&gt;<br />#include&nbsp;&lt;assert.h&gt;<br /><br /><span style="color: #0000FF; ">void</span>&nbsp;recopy2(<span style="color: #0000FF; ">char</span>&nbsp;**&nbsp;pto,&nbsp;<span style="color: #0000FF; ">char</span>&nbsp;*&nbsp;from)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>&nbsp;('\0'&nbsp;!=&nbsp;*from)<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recopy2(pto,&nbsp;from&nbsp;+&nbsp;1);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*((*pto)++)&nbsp;=&nbsp;*from;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /><span style="color: #0000FF; ">void</span>&nbsp;recopy1(<span style="color: #0000FF; ">char</span>&nbsp;*&nbsp;to,&nbsp;<span style="color: #0000FF; ">const</span>&nbsp;<span style="color: #0000FF; ">char</span>&nbsp;*&nbsp;from)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;assert(NULL&nbsp;!=&nbsp;to&nbsp;&amp;&amp;&nbsp;NULL&nbsp;!=&nbsp;from);<br />&nbsp;&nbsp;&nbsp;&nbsp;recopy2(&amp;to,&nbsp;(<span style="color: #0000FF; ">char</span>&nbsp;*)(from));<br />&nbsp;&nbsp;&nbsp;&nbsp;*to&nbsp;=&nbsp;'\0';<br />}<br /><br /><span style="color: #0000FF; ">void</span>&nbsp;main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">char</span>&nbsp;src[5]&nbsp;=&nbsp;"1234";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">char</span>&nbsp;des[6]&nbsp;=&nbsp;"abcde";<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("before:&nbsp;%s&nbsp;--&nbsp;%s\r\n",&nbsp;src,&nbsp;des);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recopy1(des,&nbsp;src);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("after:&nbsp;&nbsp;%s&nbsp;--&nbsp;%s\r\n",&nbsp;src,&nbsp;des);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">char</span>&nbsp;src[5]&nbsp;=&nbsp;"1234";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">char</span>&nbsp;des[5]&nbsp;=&nbsp;"abcd";<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("before:&nbsp;%s&nbsp;--&nbsp;%s\r\n",&nbsp;src,&nbsp;des);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;recopy1(des,&nbsp;src);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("after:&nbsp;&nbsp;%s&nbsp;--&nbsp;%s\r\n",&nbsp;src,&nbsp;des);<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</div></div><img src ="http://www.cppblog.com/jxtgddlt/aggbug/160939.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jxtgddlt/" target="_blank">メmarsメ</a> 2011-11-25 02:19 <a href="http://www.cppblog.com/jxtgddlt/archive/2011/11/25/160939.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>有一个长度为998的数组，里面是1-1000并且无重复的数。只用一次遍历，不能使用集合，算出1-1000不在这个数组中的那2个数</title><link>http://www.cppblog.com/jxtgddlt/archive/2011/11/18/160442.html</link><dc:creator>メmarsメ</dc:creator><author>メmarsメ</author><pubDate>Fri, 18 Nov 2011 04:58:00 GMT</pubDate><guid>http://www.cppblog.com/jxtgddlt/archive/2011/11/18/160442.html</guid><wfw:comment>http://www.cppblog.com/jxtgddlt/comments/160442.html</wfw:comment><comments>http://www.cppblog.com/jxtgddlt/archive/2011/11/18/160442.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jxtgddlt/comments/commentRss/160442.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jxtgddlt/services/trackbacks/160442.html</trackback:ping><description><![CDATA[<div><span style="font-family: simsun; line-height: 23px; background-color: #ffffff; ">一次遍历求出arr[998]的998个数的平方和 和 和.<br />1~1000的和为:n(1+n)/21~1000的平方和为：</span><span style="font-family: simsun; line-height: 23px; background-color: #ffffff; color: #ff0000; ">n(n+1)(2n+1)/6</span><span style="font-family: simsun; line-height: 23px; background-color: #ffffff; color: #000000; ">即可得到两个数的平方和 和 和<br /></span><span style="font-family: simsun; line-height: 23px; background-color: #ffffff; color: #000000; ">解方程即可得到结果</span><span style="font-family: simsun; line-height: 23px; background-color: #ffffff; color: #000000; "></span></div><img src ="http://www.cppblog.com/jxtgddlt/aggbug/160442.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jxtgddlt/" target="_blank">メmarsメ</a> 2011-11-18 12:58 <a href="http://www.cppblog.com/jxtgddlt/archive/2011/11/18/160442.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>概率问题，有个人每天都去看流星，他一个月能看到流星的概率是91%，那他半个月能看到流星的概率是多少？（每天能看到流星的事件是独立的）</title><link>http://www.cppblog.com/jxtgddlt/archive/2011/11/04/159597.html</link><dc:creator>メmarsメ</dc:creator><author>メmarsメ</author><pubDate>Fri, 04 Nov 2011 02:37:00 GMT</pubDate><guid>http://www.cppblog.com/jxtgddlt/archive/2011/11/04/159597.html</guid><wfw:comment>http://www.cppblog.com/jxtgddlt/comments/159597.html</wfw:comment><comments>http://www.cppblog.com/jxtgddlt/archive/2011/11/04/159597.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jxtgddlt/comments/commentRss/159597.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jxtgddlt/services/trackbacks/159597.html</trackback:ping><description><![CDATA[每天晚上出来流星出来的概率为x<br />则一个月不出来流星的概率为（1-x)^30=1-0.91=0.09<br />半个月不出来流星的概率为（1-x)^15=(1-x)^30^0.5=0.3<br />半个月看得到流星的概率为70%<br />..<br />每天看到流星的概率相同，天数越多，看到流星的概率越大！比如抽奖，抽的次数越多，中奖概率越大，30天91%，15天绝不是91%，70%为正解！<img src ="http://www.cppblog.com/jxtgddlt/aggbug/159597.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jxtgddlt/" target="_blank">メmarsメ</a> 2011-11-04 10:37 <a href="http://www.cppblog.com/jxtgddlt/archive/2011/11/04/159597.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>有2.5亿个整数存放在一个文件中，（已知内存容量没有此文件大）如何判断出这个文件中有多少个不相同的数。</title><link>http://www.cppblog.com/jxtgddlt/archive/2011/10/20/158749.html</link><dc:creator>メmarsメ</dc:creator><author>メmarsメ</author><pubDate>Thu, 20 Oct 2011 06:35:00 GMT</pubDate><guid>http://www.cppblog.com/jxtgddlt/archive/2011/10/20/158749.html</guid><wfw:comment>http://www.cppblog.com/jxtgddlt/comments/158749.html</wfw:comment><comments>http://www.cppblog.com/jxtgddlt/archive/2011/10/20/158749.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jxtgddlt/comments/commentRss/158749.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jxtgddlt/services/trackbacks/158749.html</trackback:ping><description><![CDATA[总结出一个规律，腾讯的面试题跟 数据分析处理 的相关的，基本上都会用到hash算法<br />
<table class="mtxt" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td id="rbody_76066373" csdnid="rbody_76066373">
<div class="msgfont"><span style="color: red">把整个空间映射到内存，一个整数一个bit，总共需要2^32 / 2^3 = 512M内存。</span></div><!--End_rbody_76066373//--></td></tr>
<tr>
<td csdnid="rmodify_76066373"></td></tr></tbody></table><img src ="http://www.cppblog.com/jxtgddlt/aggbug/158749.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jxtgddlt/" target="_blank">メmarsメ</a> 2011-10-20 14:35 <a href="http://www.cppblog.com/jxtgddlt/archive/2011/10/20/158749.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>骆驼吃香蕉问题</title><link>http://www.cppblog.com/jxtgddlt/archive/2011/10/08/157794.html</link><dc:creator>メmarsメ</dc:creator><author>メmarsメ</author><pubDate>Sat, 08 Oct 2011 06:52:00 GMT</pubDate><guid>http://www.cppblog.com/jxtgddlt/archive/2011/10/08/157794.html</guid><wfw:comment>http://www.cppblog.com/jxtgddlt/comments/157794.html</wfw:comment><comments>http://www.cppblog.com/jxtgddlt/archive/2011/10/08/157794.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jxtgddlt/comments/commentRss/157794.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jxtgddlt/services/trackbacks/157794.html</trackback:ping><description><![CDATA[<pre id="question-content">总共有3000只香蕉，有一只骆驼每一次只能带1000只香蕉，<br />每1公里吃1只香蕉，没有香蕉吃它是不肯走的，A-B 点距离1000公里，<br />如果这个骆驼要从A点到B点有什么办法可以让更多的香蕉剩下来？<br />如何做到？如何最有效率的运最多的香蕉到B点？</pre><br />主要解决思路： <br />&#9312;骆驼先载上1000个香蕉 走到某一处，然后放一些香蕉在路上某处。<br />再带上一些香蕉 边走边吃返回到起点 <br />&#9313;重复上述过程，直到还剩余香蕉全部都搬运到路上某处.<br />&#9314;最后重复&#9312;&#9313;过程<br /><br />现在的问题就出现了 走到某处？ 到底走到哪里呢？<br />一开始，有3000个香蕉 那么在通往终点的方向上的同一段路 要走3次<br />该段路程反方向要走2次<br />如果只剩了2000个香蕉 那么在通往终点的方向上的同一段路 要走2次<br />该段路程反方向要走1次<br /><br />很显然 可以用剩余香蕉的数量来分隔。<br /><br />从3000个香蕉到刚好剩余2000个香蕉 <br />消耗了1000个香蕉（骆驼行走路程为1000m）<br />在同一段路要走3+2=5 次<br />那么这段路只有 1000/5=200m 此时走过200m 剩余1000个香蕉<br /><br />从2000个香蕉到1000个 <br />又消耗了1000个香蕉（骆驼行走路程为1000m）<br />根据上述推论 在在同一段路要走1+2=3 次<br />那么又走过1000/3=333.3m<br /><br /><span style="color: red">因为香蕉的浪费全部都是浪费在往返的路程中,所以只要往返的路程最短就能运送最多的香蕉。</span><img src ="http://www.cppblog.com/jxtgddlt/aggbug/157794.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jxtgddlt/" target="_blank">メmarsメ</a> 2011-10-08 14:52 <a href="http://www.cppblog.com/jxtgddlt/archive/2011/10/08/157794.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>1000瓶药水，其中至多有1瓶剧毒，现在给你10只小狗在24小时内通过小狗试药的方式找出哪瓶药有毒或者全部无毒（小狗服完药20小时后才能判断是否中毒）</title><link>http://www.cppblog.com/jxtgddlt/archive/2011/10/02/157348.html</link><dc:creator>メmarsメ</dc:creator><author>メmarsメ</author><pubDate>Sun, 02 Oct 2011 06:04:00 GMT</pubDate><guid>http://www.cppblog.com/jxtgddlt/archive/2011/10/02/157348.html</guid><wfw:comment>http://www.cppblog.com/jxtgddlt/comments/157348.html</wfw:comment><comments>http://www.cppblog.com/jxtgddlt/archive/2011/10/02/157348.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cppblog.com/jxtgddlt/comments/commentRss/157348.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jxtgddlt/services/trackbacks/157348.html</trackback:ping><description><![CDATA[把狗从0-9编号<br />把药水按1-1000编号<br />把药水编号按二进制，如果第i位（因为最大1000，所以bit位为0-9）bit位为1，则分给编号为i的狗狗喝<br />最后得一二进制数，如果编号为i的狗狗死了，该数的第i bit位为1，该数就是有毒的药水编号<br /><br />每2.4分钟给一只狗狗喝一瓶药，并记录，若有狗狗中毒，查看时间记录就知道哪瓶药有毒了<br /><img src ="http://www.cppblog.com/jxtgddlt/aggbug/157348.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jxtgddlt/" target="_blank">メmarsメ</a> 2011-10-02 14:04 <a href="http://www.cppblog.com/jxtgddlt/archive/2011/10/02/157348.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>判断另一字符串的所有字母是否在母串中都有</title><link>http://www.cppblog.com/jxtgddlt/archive/2011/09/30/157222.html</link><dc:creator>メmarsメ</dc:creator><author>メmarsメ</author><pubDate>Fri, 30 Sep 2011 05:24:00 GMT</pubDate><guid>http://www.cppblog.com/jxtgddlt/archive/2011/09/30/157222.html</guid><wfw:comment>http://www.cppblog.com/jxtgddlt/comments/157222.html</wfw:comment><comments>http://www.cppblog.com/jxtgddlt/archive/2011/09/30/157222.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jxtgddlt/comments/commentRss/157222.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jxtgddlt/services/trackbacks/157222.html</trackback:ping><description><![CDATA[<div><font style="background-color: #c7edcc">
<div><font style="background-color: #c7edcc">From:</font><span class="tcnt"><font size="5" face="微软雅黑"><font style="background-color: #c7edcc">A Google Interviewing Story</font><br /></font></span>Q:<br />Say you have one string of alphabetic characters, and say you have another, guaranteed smaller string of alphabetic characters. Algorithmically speaking, what's the fastest way to find out if all the characters in the smaller string are in the larger string?</div>
<div><br /></div>
<div>For example, if the two strings were:</div>
<div><br /></div>
<div><br /></div>
<div>String 1: ABCDEFGHLMNOPQRS</div>
<div>String 2: DCGSRQPOM</div>
<div><br /></div>
<div><br /></div>
<div>You'd get true as every character in string2 is in string1. If the two strings were:</div>
<div><br /></div>
<div><br /></div>
<div>String 1: ABCDEFGHLMNOPQRS</div>
<div>String 2: DCGSRQPOZ</div>
<div><br />A:<br />Finally, I told him the best method would simply be O(n+m). That is, iterate through the first string and put each character in a <strong>hashtable</strong> (cost of O(n) or 16). Then iterate the 2nd string and query the hashtable for each character you find. If its not found, you don't have a match. That would cost 8 operations - so both operations together is a total of 24 operations. Not bad and way better than the other solutions.<br /><br /><br />
<div><strong>He stepped up to the whiteboard, "What if - given that we have a limited range of possible characters - I assigned each character of the alphabet to a prime number starting with 2 and going up from there. So A would be 2, and B would be 3, and C would be 5, etc. And then I went through the first string and 'multiplied' each character's prime number together. You'd end up with some big number right? And then - what if I iterated through the 2nd string and 'divided' by every character in there</strong>. If any division gave a remainder - you knew you didn't have a match. If there was no remainders through the whole process, you knew you had a subset. Would that work?"</div>
<div><br /></div>
<div>Every once in awhile - someone thinks so fantastically far out of your box you really need a minute to catch up. And now that he was standing, his leather pants weren't helping with this.</div>
<div><br /></div>
<div>Now mind you - Guy's solution (and of course, needless to say I doubt Guy was the first to ever think of this) was algorithmically speaking no better than mine. Even practically, you'd still probably use mine as it was more general and didn't make you deal with messy <strong>big integers</strong>. But on the "clever scale", Guy's was way, way, (way) more fun.</div><br /></div>
<div><br /></div>
<div>you'd get false as Z isn't in the first string.<br /></font></div></div><img src ="http://www.cppblog.com/jxtgddlt/aggbug/157222.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jxtgddlt/" target="_blank">メmarsメ</a> 2011-09-30 13:24 <a href="http://www.cppblog.com/jxtgddlt/archive/2011/09/30/157222.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数列L中有n个整数，其中K个数字出现了两次，1个数字出现了一次，所以n=2k+1；请在使用O（1）空间的前提下，尽快找出只出现一次的那个数字，并说明算法的复杂度。</title><link>http://www.cppblog.com/jxtgddlt/archive/2011/09/19/156257.html</link><dc:creator>メmarsメ</dc:creator><author>メmarsメ</author><pubDate>Mon, 19 Sep 2011 11:28:00 GMT</pubDate><guid>http://www.cppblog.com/jxtgddlt/archive/2011/09/19/156257.html</guid><wfw:comment>http://www.cppblog.com/jxtgddlt/comments/156257.html</wfw:comment><comments>http://www.cppblog.com/jxtgddlt/archive/2011/09/19/156257.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/jxtgddlt/comments/commentRss/156257.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/jxtgddlt/services/trackbacks/156257.html</trackback:ping><description><![CDATA[数列L中有n个整数，其中K个数字出现了两次，1个数字出现了一次，所以n=2k+1；请在使用O（1）空间的前提下，尽快找出只出现一次的那个数字，并说明算法的复杂度。<br /><br />既然是空间复杂度的限制<br />所以&nbsp;
<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 />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;res&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /><img id="Codehighlighter1_41_59_Open_Image" onclick="this.style.display='none'; Codehighlighter1_41_59_Open_Text.style.display='none'; Codehighlighter1_41_59_Closed_Image.style.display='inline'; Codehighlighter1_41_59_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_41_59_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_41_59_Closed_Text.style.display='none'; Codehighlighter1_41_59_Open_Image.style.display='inline'; Codehighlighter1_41_59_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">for</span><span style="color: #000000">(&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;n;&nbsp;i</span><span style="color: #000000">++</span><span style="color: #000000">&nbsp;)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_41_59_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_41_59_Open_Text"><span style="color: #000000">{<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;res&nbsp;</span><span style="color: #000000">^=</span><span style="color: #000000">&nbsp;arr[i];<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;res;</span></div>最终有<br />1.两个相同的数异或结果为0<br />2.0与任何数异或结果还是这个数<img src ="http://www.cppblog.com/jxtgddlt/aggbug/156257.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/jxtgddlt/" target="_blank">メmarsメ</a> 2011-09-19 19:28 <a href="http://www.cppblog.com/jxtgddlt/archive/2011/09/19/156257.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>