Light OJ 1006 - Hex-a-bonacci
題目鏈接:http://acm.hust.edu.cn/vjudge/contest/121396#problem/G
http://lightoj.com/volume_showproblem.php?problem=1006
密碼:acm
Description
Given a code (not optimized), and necessary inputs, you have to find the output of the code for the inputs. The code is as follows:
int a, b, c, d, e, f;
int fn( int n ) {
if( n == ) return a;
if( n == ) return b;
if( n == ) return c;
if( n == ) return d;
if( n == ) return e;
if( n == ) return f;
return( fn(n-) + fn(n-) + fn(n-) + fn(n-) + fn(n-) + fn(n-) );
}
int main() {
int n, caseno = , cases;
scanf("%d", &cases);
while( cases-- ) {
scanf("%d %d %d %d %d %d %d", &a, &b, &c, &d, &e, &f, &n);
printf("Case %d: %d\n", ++caseno, fn(n) % );
}
return ;
}
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case contains seven integers, a, b, c, d, e, f and n. All integers will be non-negative and 0 ≤ n ≤ 10000 and the each of the others will be fit into a 32-bit integer.
Output
For each case, print the output of the given code. The given code may have integer overflow problem in the compiler, so be careful.
分析:改善整數溢出情況
*:數組、求余
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream> using namespace std; #define N 11000 int a[N]; int main()
{
int T,k=,i,n; scanf("%d", &T); while(T--)
{
for(i=;i<;i++)
{
scanf("%d", &a[i]);
a[i]%=;///取余是必須滴
} scanf("%d", &n); for(i=;i<=n;i++)
{
a[i]=(a[i-]+a[i-]+a[i-]+a[i-]+a[i-]+a[i-])%;
} printf("Case %d: %d\n", k++, a[n]);
}
}
總結
以上是生活随笔為你收集整理的Light OJ 1006 - Hex-a-bonacci的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 金州陆军学院是干嘛的
- 下一篇: UITableView 详解 ()