[問題] 開根號
要做一個開根號的function,速度要跟之前的get_day_of_month(註1)一樣快,至少接近
參數的有效範圍0~4000
已給的程式碼:
inline float sqrt(int num)
{
.
.
.
.
}
int main(void)
{
flaot ans;
ans= sqrt(58);
cout<<ans<<endl;
}
輸出結果
7.61.....
題目要求
main 中不做任何修改或增加程式碼
不要呼叫c lib的sqrt(); (一定慢)
不要花費數小時時間鍵入4000個array table
(註1) get_day_of_month(int start_ month , int end_month);
是一個傳入 起迄月份得總日數的function
速度方面我當時是用 gobal value 設累加日數array,減少每次函數配置array時間
再用#define 巨集來取代get_day_of_month
比使用一個函數並在其中設array 快了30倍
==========================================================================
不使用lib sqrt的寫法我寫過,google也很多
但是都要用到很多迴圈,這樣一來速度一定不可能快 (是吧?)
題目又有特別提說不要用array[4000](雖然我也不會這麼做)
又程式有特別給了參數範圍,並非一般的開根號程式,加上有要求速度
請問各位對於這題的看法是?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.0.34.42
→
08/26 12:20, , 1F
08/26 12:20, 1F
→
08/26 12:20, , 2F
08/26 12:20, 2F
推
08/26 12:29, , 3F
08/26 12:29, 3F
→
08/26 12:30, , 4F
08/26 12:30, 4F
→
08/26 12:39, , 5F
08/26 12:39, 5F
→
08/26 12:40, , 6F
08/26 12:40, 6F
→
08/26 12:42, , 7F
08/26 12:42, 7F
→
08/26 12:42, , 8F
08/26 12:42, 8F
→
08/26 12:44, , 9F
08/26 12:44, 9F
→
08/26 12:44, , 10F
08/26 12:44, 10F
→
08/26 12:44, , 11F
08/26 12:44, 11F
→
08/26 12:44, , 12F
08/26 12:44, 12F
→
08/26 12:59, , 13F
08/26 12:59, 13F
→
08/26 13:03, , 14F
08/26 13:03, 14F
→
08/26 13:04, , 15F
08/26 13:04, 15F
→
08/26 13:10, , 16F
08/26 13:10, 16F
→
08/26 13:11, , 17F
08/26 13:11, 17F
→
08/26 13:12, , 18F
08/26 13:12, 18F
→
08/26 13:16, , 19F
08/26 13:16, 19F
→
08/26 13:17, , 20F
08/26 13:17, 20F
→
08/26 13:17, , 21F
08/26 13:17, 21F
→
08/26 13:18, , 22F
08/26 13:18, 22F
→
08/26 13:19, , 23F
08/26 13:19, 23F
→
08/26 13:20, , 24F
08/26 13:20, 24F
→
08/26 13:22, , 25F
08/26 13:22, 25F
→
08/26 13:22, , 26F
08/26 13:22, 26F
→
08/26 13:23, , 27F
08/26 13:23, 27F
→
08/26 13:23, , 28F
08/26 13:23, 28F
→
08/26 13:24, , 29F
08/26 13:24, 29F
→
08/26 13:24, , 30F
08/26 13:24, 30F
→
08/26 13:25, , 31F
08/26 13:25, 31F
→
08/26 13:26, , 32F
08/26 13:26, 32F
→
08/26 13:26, , 33F
08/26 13:26, 33F
→
08/26 13:26, , 34F
08/26 13:26, 34F
→
08/26 13:26, , 35F
08/26 13:26, 35F
→
08/26 13:27, , 36F
08/26 13:27, 36F
→
08/26 13:29, , 37F
08/26 13:29, 37F
→
08/26 13:30, , 38F
08/26 13:30, 38F
→
08/26 13:31, , 39F
08/26 13:31, 39F
還有 22 則推文
→
08/26 15:23, , 62F
08/26 15:23, 62F
→
08/26 15:23, , 63F
08/26 15:23, 63F
→
08/26 15:26, , 64F
08/26 15:26, 64F
→
08/26 15:34, , 65F
08/26 15:34, 65F
推
08/26 15:44, , 66F
08/26 15:44, 66F
→
08/26 15:45, , 67F
08/26 15:45, 67F
推
08/26 15:49, , 68F
08/26 15:49, 68F
推
08/26 16:02, , 69F
08/26 16:02, 69F
→
08/26 16:17, , 70F
08/26 16:17, 70F
→
08/26 16:18, , 71F
08/26 16:18, 71F
→
08/26 16:19, , 72F
08/26 16:19, 72F
→
08/26 16:44, , 73F
08/26 16:44, 73F
推
08/26 16:55, , 74F
08/26 16:55, 74F
推
08/26 16:57, , 75F
08/26 16:57, 75F
→
08/26 16:57, , 76F
08/26 16:57, 76F
→
08/26 17:03, , 77F
08/26 17:03, 77F
推
08/26 17:08, , 78F
08/26 17:08, 78F
→
08/26 17:46, , 79F
08/26 17:46, 79F
→
08/26 17:47, , 80F
08/26 17:47, 80F
→
08/26 17:47, , 81F
08/26 17:47, 81F
→
08/26 17:47, , 82F
08/26 17:47, 82F
→
08/26 17:48, , 83F
08/26 17:48, 83F
→
08/26 17:49, , 84F
08/26 17:49, 84F
→
08/26 17:54, , 85F
08/26 17:54, 85F
→
08/26 18:03, , 86F
08/26 18:03, 86F
→
08/26 18:12, , 87F
08/26 18:12, 87F
→
08/26 18:13, , 88F
08/26 18:13, 88F
→
08/26 18:17, , 89F
08/26 18:17, 89F
→
08/26 18:27, , 90F
08/26 18:27, 90F
→
08/26 19:17, , 91F
08/26 19:17, 91F
→
08/26 19:21, , 92F
08/26 19:21, 92F
→
08/26 19:33, , 93F
08/26 19:33, 93F
→
08/26 19:35, , 94F
08/26 19:35, 94F
→
08/26 19:37, , 95F
08/26 19:37, 95F
→
08/26 19:38, , 96F
08/26 19:38, 96F
→
08/27 10:39, , 97F
08/27 10:39, 97F
→
08/27 10:40, , 98F
08/27 10:40, 98F
→
08/27 10:40, , 99F
08/27 10:40, 99F
→
08/27 10:47, , 100F
08/27 10:47, 100F
→
08/27 10:48, , 101F
08/27 10:48, 101F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章