我不知道該怎麼用幾何解釋會比較好。
因此很多人遇到這題我想就只能用猜測的方法,
假設圓的數量(x)與區域的數量(y)的關係是個二次函數:y = ax^2 + bx + c
那麼
x = 1 => y = a+b+c = 2 --(1)
x = 2 => y = 4a+2b+c = 4 --(2)
x = 3 => y = 9a+3b+c = 8 --(3)
x = 4 => y = 16a+4b+c = 14 --(4)
其實只需要3個就可以了,我就用(1)(2)(3)好了。
首先
(2) - (1) : 3a+b = 2 --(5)
(3) - (2) : 5a+b = 4 --(6)
再來
(6) - (5) : 2a = 2 => a = 1
a=1代入(5)
則b = 2-3 = -1
再將a=1和b=-1代入(1)
則c = 2
因此可以得出 y = x^2 - x + 2 的式子,即得解。
[C++](30ms, 704KB)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
int main() | |
{ | |
int n; | |
while( cin >> n ) | |
cout << n*(n-1)+2 << endl; | |
return 0; | |
} |
0 意見:
張貼留言