題意:
(from luckycat)
解法:
將 x 代入多項式。
TAG: Math,
注意:
程式碼:
This file contains 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
/** | |
* 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; | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽