<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>「[轉載]學程式設計的人不能不看的好文章」的迴響</title>
	<atom:link href="http://www.vixual.net/blog/archives/99/feed" rel="self" type="application/rss+xml" />
	<link>http://www.vixual.net/blog/archives/99</link>
	<description>網路、空氣、水</description>
	<lastBuildDate>Sun, 22 Aug 2010 16:22:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>由：Simon Ho</title>
		<link>http://www.vixual.net/blog/archives/99#comment-710</link>
		<dc:creator>Simon Ho</dc:creator>
		<pubDate>Thu, 05 Aug 2010 12:54:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.vixual.net/blog/?p=99#comment-710</guid>
		<description>很有趣...我也來賣弄一下

// using logic instructions.
inline long fn(long n)
{
    return  n&amp;1 ? ((n+1)&gt;&gt;1):-((n+1)&gt;&gt;1) ;
}

// using inline asm. 
long fn(long n)
{
    __asm{
        mov eax,n    ; Load n to AX
        inc eax      ; AX = AX + 1.
        shr eax,1    ; AX divides by 2.
        jnc EXIT     ; Exit if AX is a odd number.
        neg eax      ; AX = -AX ;
EXIT:
    }
}</description>
		<content:encoded><![CDATA[Using <img src='http://www.vixual.net/blog/wp-content/plugins/browser-sniff/icons/ie.png' alt='Internet Explorer' width='14' height='14' class='browsericon' /> Internet Explorer 7.0 on  <img src='http://www.vixual.net/blog/wp-content/plugins/browser-sniff/icons/windows.png' alt='Windows' width='14' height='14' class='browsericon' />  Windows XP<p>
很有趣&#8230;我也來賣弄一下</p>
<p>// using logic instructions.<br />
inline long fn(long n)<br />
{<br />
    return  n&amp;1 ? ((n+1)&gt;&gt;1):-((n+1)&gt;&gt;1) ;<br />
}</p>
<p>// using inline asm.<br />
long fn(long n)<br />
{<br />
    __asm{<br />
        mov eax,n    ; Load n to AX<br />
        inc eax      ; AX = AX + 1.<br />
        shr eax,1    ; AX divides by 2.<br />
        jnc EXIT     ; Exit if AX is a odd number.<br />
        neg eax      ; AX = -AX ;<br />
EXIT:<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>由：JonesLai</title>
		<link>http://www.vixual.net/blog/archives/99#comment-707</link>
		<dc:creator>JonesLai</dc:creator>
		<pubDate>Wed, 04 Aug 2010 05:05:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.vixual.net/blog/?p=99#comment-707</guid>
		<description>long fn(unsigned long n){
	return (long)n/2*(-1)+((n%2)?n:0);
}

型別有考慮進去，根本不需要考慮輸入負數產生的影響。</description>
		<content:encoded><![CDATA[Using <img src='http://www.vixual.net/blog/wp-content/plugins/browser-sniff/icons/firefox.png' alt='Mozilla Firefox' width='14' height='14' class='browsericon' /> Mozilla Firefox 3.6.8 on  <img src='http://www.vixual.net/blog/wp-content/plugins/browser-sniff/icons/windows.png' alt='Windows' width='14' height='14' class='browsericon' />  Windows XP<p>
long fn(unsigned long n){<br />
	return (long)n/2*(-1)+((n%2)?n:0);<br />
}</p>
<p>型別有考慮進去，根本不需要考慮輸入負數產生的影響。</p>
]]></content:encoded>
	</item>
	<item>
		<title>由：JonesLai</title>
		<link>http://www.vixual.net/blog/archives/99#comment-706</link>
		<dc:creator>JonesLai</dc:creator>
		<pubDate>Wed, 04 Aug 2010 04:05:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.vixual.net/blog/?p=99#comment-706</guid>
		<description>egg說法有錯，型別為long，本來就會無條件捨去。
效果等同底下吧～
if(0==n%2)	return (n/2)*(-1);
else		return ((n+1)/2);

事實上還可以再簡約一點：
(n/2)*(-1)+(n%2)?n:0;
這樣就好了～哈
這都是事後諸葛亮了吧～
面試一緊張有些就什麼都忘了的說～</description>
		<content:encoded><![CDATA[Using <img src='http://www.vixual.net/blog/wp-content/plugins/browser-sniff/icons/firefox.png' alt='Mozilla Firefox' width='14' height='14' class='browsericon' /> Mozilla Firefox 3.6.8 on  <img src='http://www.vixual.net/blog/wp-content/plugins/browser-sniff/icons/windows.png' alt='Windows' width='14' height='14' class='browsericon' />  Windows XP<p>
egg說法有錯，型別為long，本來就會無條件捨去。<br />
效果等同底下吧～<br />
if(0==n%2)	return (n/2)*(-1);<br />
else		return ((n+1)/2);</p>
<p>事實上還可以再簡約一點：<br />
(n/2)*(-1)+(n%2)?n:0;<br />
這樣就好了～哈<br />
這都是事後諸葛亮了吧～<br />
面試一緊張有些就什麼都忘了的說～</p>
]]></content:encoded>
	</item>
	<item>
		<title>由：程式鄉巴佬</title>
		<link>http://www.vixual.net/blog/archives/99#comment-703</link>
		<dc:creator>程式鄉巴佬</dc:creator>
		<pubDate>Wed, 14 Jul 2010 09:27:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.vixual.net/blog/?p=99#comment-703</guid>
		<description>我是個初學者，我也有了錯誤的觀念了…我也以為程式碼的簡短就是好…看了版主的這些文章後，才知道並非如此…</description>
		<content:encoded><![CDATA[Using <img src='http://www.vixual.net/blog/wp-content/plugins/browser-sniff/icons/firefox.png' alt='Mozilla Firefox' width='14' height='14' class='browsericon' /> Mozilla Firefox 3.6.6 on  <img src='http://www.vixual.net/blog/wp-content/plugins/browser-sniff/icons/windows.png' alt='Windows' width='14' height='14' class='browsericon' />  Windows XP<p>
我是個初學者，我也有了錯誤的觀念了…我也以為程式碼的簡短就是好…看了版主的這些文章後，才知道並非如此…</p>
]]></content:encoded>
	</item>
	<item>
		<title>由：egg</title>
		<link>http://www.vixual.net/blog/archives/99#comment-134</link>
		<dc:creator>egg</dc:creator>
		<pubDate>Sat, 20 Sep 2008 17:43:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.vixual.net/blog/?p=99#comment-134</guid>
		<description>long fn(long n) {
  if(n 0);
    exit(1);
  }
  if(0==n%2)
    return (n/2)*(-1);
  else
    return (n/2)*(-1)+n;
}


在爬文時看到這篇
有個小小的錯誤

  if(0==n%2)
    return (n/2)*(-1);
  else
    return (n/2-0.5)*(-1)+n;

當N為單數時,要捨去</description>
		<content:encoded><![CDATA[Using <img src='http://www.vixual.net/blog/wp-content/plugins/browser-sniff/icons/ie.png' alt='Internet Explorer' width='14' height='14' class='browsericon' /> Internet Explorer 6.0 on  <img src='http://www.vixual.net/blog/wp-content/plugins/browser-sniff/icons/windows.png' alt='Windows' width='14' height='14' class='browsericon' />  Windows XP<p>
long fn(long n) {<br />
  if(n 0);<br />
    exit(1);<br />
  }<br />
  if(0==n%2)<br />
    return (n/2)*(-1);<br />
  else<br />
    return (n/2)*(-1)+n;<br />
}</p>
<p>在爬文時看到這篇<br />
有個小小的錯誤</p>
<p>  if(0==n%2)<br />
    return (n/2)*(-1);<br />
  else<br />
    return (n/2-0.5)*(-1)+n;</p>
<p>當N為單數時,要捨去</p>
]]></content:encoded>
	</item>
	<item>
		<title>由：Anonymous</title>
		<link>http://www.vixual.net/blog/archives/99#comment-4</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 30 Oct 2007 03:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.vixual.net/blog/?p=99#comment-4</guid>
		<description>程式設計師本來就必須要想到程式的執行效率，尤其是設計有關數學演算法的問題。
在BigO(1) 做得完的事情, 就沒有必要花費BigO(n) 去做。1-2+3-4+5-6+7......+n看就知道兩組當一項都是-1, 當然是一道簡化的數學式即可算出，根本就不需要使用迴圈去計算。
更例如算費氏數列，絕大多數人都使用遞迴計算，但是n帶很大的時候，效率卻差到不行;但是事實上不論n多少, 是有BigO(1)就計算出來的作法。有規則的東西都幾乎可以用BigO(1)的演算法來計算得到結果，就端看設計者的功力和數學好不好而定。</description>
		<content:encoded><![CDATA[<p>
程式設計師本來就必須要想到程式的執行效率，尤其是設計有關數學演算法的問題。<br />
在BigO(1) 做得完的事情, 就沒有必要花費BigO(n) 去做。1-2+3-4+5-6+7&#8230;&#8230;+n看就知道兩組當一項都是-1, 當然是一道簡化的數學式即可算出，根本就不需要使用迴圈去計算。<br />
更例如算費氏數列，絕大多數人都使用遞迴計算，但是n帶很大的時候，效率卻差到不行;但是事實上不論n多少, 是有BigO(1)就計算出來的作法。有規則的東西都幾乎可以用BigO(1)的演算法來計算得到結果，就端看設計者的功力和數學好不好而定。</p>
]]></content:encoded>
	</item>
</channel>
</rss>
