日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Light OJ 1006 - Hex-a-bonacci

發布時間:2024/8/24 编程问答 31 如意码农
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。