• UVA12653 Buses


    Problem H
    Buses
    File: buses.[c|cpp|java]
    Programming competitions usually require infrastructure and organization on the part of those
    responsible. A problem that frequently must be solved is regarding transportation. While participating
    in a recent competition, Ricardinho watched the buses and micro-buses used in the transportation of
    competitors, all lined up one behind the other as competitors disembarked. The vehicles were all from
    the same company, although had different paintings. Ricardinho began to wonder how many ways
    that line could be formed using buses and minibuse from that company.
    Each bus is 10 meters long, each minibus is 5 meters long. Given the total length of a line of buses
    and minibuses, and the number of different colors each buse or minibus may be painted, Ricardinho
    wants to know in how many ways such a line can be formed.
    Input
    The input contains several test cases. Each test case is composed of a single line, containing three
    integers N, K and L, representing respectively the total length, in meters, of the line Ricky is con-sidering, K indicates the number of different colors for micro-buses, and L represents the number of
    different colors for buses. Note that, as integers N , K and L may be very large, the use of 64 bits
    integers is recommended.
    Output
    As the number of different ways of forming the line can be very large, Ricardinho is interested in the
    last 6 digits of that quantity. Thus, your for each test case your program must produce a single line
    containing exactly 6 digits, corresponding to the last digits of the solution.
    Restrictions
    • 5 ≤ N ≤ 10
    15
    and N is multiple of 5
    • 1 ≤ K ≤ 10
    15
    • 1 ≤ L ≤ 10
    15
    Examples
    Input
    25 5 5
    5 1000 1000
    20 17 31
    15 9 2
    Output
    006000
    001000
    111359
    000765

    #include <iostream>
    #include <stdio.h>
    #include <queue>
    #include <stdio.h>
    #include <string.h>
    #include <vector>
    #include <queue>
    #include <set>
    #include <algorithm>
    #include <map>
    #include <stack>
    #include <math.h>
    #define Max(a,b) ((a)>(b)?(a):(b))
    #define Min(a,b) ((a)<(b)?(a):(b))
    using namespace std ;
    typedef long long LL ;
    const int M=200008 ;
    const LL Mod=1000000 ;
    LL A[M] ;
    struct Mat{
        LL num[3][3] ;
        Mat(){} ;
        Mat(int a11 ,int a12 ,int a21 ,int a22){
             num[1][1]=a11 ;
             num[1][2]=a12 ;
             num[2][1]=a21 ;
             num[2][2]=a22 ;
        }
        Mat operator *(Mat &B){
            Mat ans(0,0,0,0) ;
            for(int i=1 ;i<=2 ;i++)
              for(int j=1;j<=2 ;j++)
                 for(int k=1;k<=2; k++){
                    ans.num[i][j]=ans.num[i][j]+num[i][k]*B.num[k][j] ;
                    if(ans.num[i][j]>=Mod)
                        ans.num[i][j]%=Mod ;
            }
            return ans ;
       }
    };
    Mat Pow(Mat X ,LL y){
        Mat ans=Mat(1,0,0,1) ;
        for(;y;y>>=1){
            if(y&1)
               ans=ans*X ;
            X=X*X ;
        }
        return ans ;
    }
    LL a[3] ;
    int main(){
       LL N ,K ,L ;
       while(cin>>N>>K>>L){
           N/=5 ;
           Mat A(K%Mod ,L%Mod ,1 ,0) ;
           a[1]=K%Mod ;
           a[2]=(((K%Mod)*(K%Mod))%Mod+L%Mod)%Mod  ;
           if(N==1)
               printf("%06d
    ",(int)a[1]) ;
           else if(N==2)
               printf("%06d
    ",(int)a[2]) ;
           else{
               A=Pow(A,N-2) ;
               LL ans=(A.num[1][1]*a[2]%Mod+A.num[1][2]*a[1]%Mod)%Mod ;
               printf("%06d
    ",(int)ans) ;
           }
       }
       return 0 ;
    }
  • 相关阅读:
    Linux九阴真经之催心掌残卷5(正则表达式)
    Linux九阴真经之催心掌残卷4(grep文本处理 )
    Linux九阴真经之催心掌残卷3
    Linux九阴真经之催心掌残卷2
    0.1.kubeadm快速部署kubernetes
    0.2.kubeadm搭建kubernetes高可用集群(CentOS)
    Nginx——模块(1)
    Nginx——主配置段
    Nginx——安装
    Nginx——I/O模型
  • 原文地址:https://www.cnblogs.com/liyangtianmen/p/3382911.html
Copyright © 2020-2023  润新知