2015 Multi-University Training Contest 5 1009 MZL's Border

简介: MZL's Border  Problem's Link:  http://acm.hdu.edu.cn/showproblem.php?pid=5351   Mean:  给出一个类似斐波那契数列的字符串序列,要你求给出的f[n]字符串中截取前m位的字符串s中s[1...i] = s[s.size()-i+1....s.size()]的最大长度。

MZL's Border 

Problem's Link:  http://acm.hdu.edu.cn/showproblem.php?pid=5351


 

Mean: 

给出一个类似斐波那契数列的字符串序列,要你求给出的f[n]字符串中截取前m位的字符串s中s[1...i] = s[s.size()-i+1....s.size()]的最大长度。

analyse:

  过计算可以发现,b字符串的前缀都是相同的,所以只要求出m的LBorder就行,和n是无关的,打表找出规律,找出对应不同的m,LBorder的值.

Time complexity: O(N)

 

Source code: 

import java.math.BigInteger;
import java.util.Scanner;


public class Main {

    static BigInteger [] fib1 = new BigInteger [ 1010 ];
    static BigInteger [] fib2 = new BigInteger [ 1010 ];
    static BigInteger [] fib3 = new BigInteger [ 1010 ];

    public static void main( String [] args) {
        fib1 [ 1 ] = new BigInteger( "2");
        fib1 [ 2 ] = new BigInteger( "2");
        fib2 [ 1 ] = BigInteger . ONE;
        fib2 [ 2 ] = BigInteger . ONE;
        fib3 [ 1 ] = BigInteger . ZERO;
        fib3 [ 2 ] = BigInteger . ONE;

        for ( int i = 3; i <= 1005; i ++) {
            fib1 [ i ] = fib1 [ i - 1 ]. add( fib1 [ i - 2 ]);
            fib2 [ i ] = fib2 [ i - 1 ]. add( fib2 [ i - 2 ]);
        }
        for ( int i = 3; i <= 1005; i ++) {
            fib3 [ i ] = fib3 [ i - 1 ]. add( fib2 [ i - 1 ]);
        }

        Scanner in = new Scanner( System . in);
        int t = in . nextInt();
        for ( int cas = 0; cas < t; ++ cas) {
            BigInteger m;
            int n = in . nextInt (), i;
            m = in . nextBigInteger();
            for ( i = 1; i <= 1005; i ++) {
                if ( m . compareTo( fib1 [ i ]) == 1) {
                    m = m . subtract( fib1 [ i ]);
                } else break;
            }
            if ( m . compareTo( fib1 [ i ]. divide( new BigInteger( "2"))) == 1) {
                m = m . subtract( fib1 [ i ]. divide( new BigInteger( "2")));
                BigInteger ans = m . add( fib3 [ i ]);
                ans = ans . subtract( BigInteger . ONE);
                ans = ans . remainder( new BigInteger( "258280327"));
                System . out . println( ans . toString());
            } else {
                BigInteger ans = m . add( fib3 [ i ]);
                ans = ans . subtract( BigInteger . ONE);
                ans = ans . remainder( new BigInteger( "258280327"));
                System . out . println( ans . toString());
            }
        }
    }
}

 

目录
相关文章
|
Java
HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube
HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube
128 0
HDU - 2018 Multi-University Training Contest 3 - 1012: Visual Cube
|
Java
HDU - 2018 Multi-University Training Contest 1 - 1001: Maximum Multiple
HDU - 2018 Multi-University Training Contest 1 - 1001: Maximum Multiple
97 0
|
Java
HDU - 2018 Multi-University Training Contest 2 - 1010: Swaps and Inversions
HDU - 2018 Multi-University Training Contest 2 - 1010: Swaps and Inversions
107 0
|
Java
HDU - 2018 Multi-University Training Contest 2 - 1004: Game
HDU - 2018 Multi-University Training Contest 2 - 1004: Game
101 0
|
Java
2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】
CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 127    Accepted Submission(s): 20 Pro...
1411 0
2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】
Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 513    Accepted Submission(s): ...
1180 0
|
Java
2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】
Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1354    Accepted Submission(s): 496 Problem Description Mr.
1298 0
|
Java
2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】
FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1060    Accepted Submission(...
1206 0