zoukankan      html  css  js  c++  java
  • 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 ;
    }
  • 相关阅读:
    Duang~Duang~Duang 还在使用jsfiddle和jsbin做在线前端代码展示和演示吗? 试试更强大的在线代码分享工具吧!
    如数据库一般访问互联网资源
    HTML5来了,7个混合式移动开发框架
    Three.js纹理贴图正方体旋转动画效果
    极客Web开发资源大荟萃#003
    精彩代码回放:jQuery实现的浏览器类型和版本检测
    响应式的全屏背景图片效果
    Delphi多线程编程之同步读写全局数据
    delphi与sqlite
    Delphi调用IE打开网页
  • 原文地址:https://www.cnblogs.com/liyangtianmen/p/3382911.html
Copyright © 2011-2022 走看看