Re: [問題] 面試考題 程式最佳化
※ 引述《DrStein (啤酒肚)》之銘言:
: 改下題目 設 a b 是 short
: 不然玩不下去
vc2008吃不下 int[UINT_MAX]
1.
static const unsigned short div24[USHRT_MAX] ={
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
.....
};
if( div24[a] > b) return 1;
2.
static const unsigned int div1024mul10[USHRT_MAX] = {
0,0,0,0,0,......
10,10,10,10,10,......
20,20,20,20,20,......
.......
}
a = div1024mul10[b];
不考慮compiler和硬體限制的話1.還可以再更快一點
用 bool[UINT_MAX][UINT_MAX]
反正這種題目根本就無視compiler的存在
話說這些資料能用macro寫嗎?
boost::preprocessor好像有loop可以用
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.219.157.175
→
06/15 12:03, , 1F
06/15 12:03, 1F
討論串 (同標題文章)