我是個對電腦科學有興趣的學生,我會貼上我的學習歷程及生活心情,也請大大們多多指教。 :)

2015年6月2日 星期二

[UVa] 10268 - 498-bis

題目網址: https://goo.gl/L6gCt8


題意:
(from luckycat)


解法:
將 x 代入多項式。

TAG: Math,

注意:

程式碼:
/**
* Tittle: 10268 - 498-bis
* Author: Cheng-Shih, Wong
* Date: 2015/05/02
*/
// include files
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
// definitions
#define FOR(i,a,b) for( int i=(a),_n=(b); i<=_n; ++i )
#define clr(x,v) memset( x, v, sizeof(x) )
typedef vector<int> VI;
// declarations
int x;
int ans;
// functions
void solve( void )
{
static int tmp, base, cnt;
static VI bucket;
bucket.clear();
scanf( "%d", &tmp );
bucket.push_back(tmp);
while( getchar()!='\n' ) {
scanf( "%d", &tmp );
bucket.push_back(tmp);
}
ans = 0;
cnt = base = 1;
for( int i = bucket.size()-2; i>=0; --i ) {
ans += cnt*bucket[i]*base;
++cnt;
base *= x;
}
printf( "%d\n", ans );
}
// main function
int main( void )
{
// input
while( scanf( "%d", &x )==1 ) {
solve();
}
return 0;
}

沒有留言:

張貼留言

任何意見都樂意傾聽