zoukankan      html  css  js  c++  java
  • Light OJ 1006

    题目链接: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 == 0 ) return a;
        if( n == 1 ) return b;
        if( n == 2 ) return c;
        if( n == 3 ) return d;
        if( n == 4 ) return e;
        if( n == 5 ) return f;
        return( fn(n-1) + fn(n-2) + fn(n-3) + fn(n-4) + fn(n-5) + fn(n-6) );
    }
    int main() {
        int n, caseno = 0, 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
    ", ++caseno, fn(n) % 10000007);
        }
        return 0;
    }

    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.

    分析:改善整数溢出情况

    *:数组、求余

     1 #include<stdio.h>
     2 #include<math.h>
     3 #include<string.h>
     4 #include<stdlib.h>
     5 #include<algorithm>
     6 #include<iostream>
     7 
     8 using namespace std;
     9 
    10 #define N 11000
    11 
    12 int a[N];
    13 
    14 int main()
    15 {
    16     int T,k=1,i,n;
    17 
    18     scanf("%d", &T);
    19 
    20     while(T--)
    21     {
    22         for(i=0;i<6;i++)
    23         {
    24             scanf("%d", &a[i]);
    25             a[i]%=10000007;///取余是必须滴
    26         }
    27 
    28         scanf("%d", &n);
    29 
    30         for(i=6;i<=n;i++)
    31         {
    32             a[i]=(a[i-1]+a[i-2]+a[i-3]+a[i-4]+a[i-5]+a[i-6])%10000007;
    33         }
    34 
    35         printf("Case %d: %d
    ", k++, a[n]);
    36     }
    37 }
  • 相关阅读:
    leetcode 33. Search in Rotated Sorted Array
    leetcode 28. Implement strStr()
    Scala函数
    布隆过滤器相关知识
    Storm 流式计算框架
    java高并发核心类 AQS(Abstract Queued Synchronizer)抽象队列同步器
    操作系统类型&操作系统结构&现代操作系统基本特征
    Kafka笔记
    Redis shell
    Lucene笔记
  • 原文地址:https://www.cnblogs.com/weiyuan/p/5731687.html
Copyright © 2011-2022 走看看