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\n",(int)a[1]) ;
       else if(N==2)
           printf("%06d\n",(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\n",(int)ans) ;
       }
   }
   return 0 ;
}

 

转载于:https://www.cnblogs.com/liyangtianmen/p/3382911.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值