博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA12653 Buses
阅读量:7282 次
发布时间:2019-06-30

本文共 3023 字,大约阅读时间需要 10 分钟。

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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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

你可能感兴趣的文章
nginx启动脚本
查看>>
linux 出现bash: ****: /lib64/ld-linux-x86-64.so.2: bad ELF interpreter: No such file or directory
查看>>
kickstart安装linux
查看>>
蓝色心情win7主题一键安装包 v 2.0
查看>>
MySQL5.7修改密码
查看>>
10个趣味Linux动画命令
查看>>
Linux协议栈(4)——sk_buff及代码
查看>>
DDOS防御
查看>>
python 学习笔记
查看>>
python的property语法的使用
查看>>
Gartner新报告: IaaS营收增长迅速 云计算市场2020年达4千亿
查看>>
照片美妆---卷积“换脸”
查看>>
linux内存管理
查看>>
Nginx配置文件nginx.conf详解
查看>>
常见的几种系统平台及文件系统
查看>>
oracle database guard
查看>>
TortoiseGit之配置密钥
查看>>
linux下apache+php安装常见问题
查看>>
ubuntu常用命令
查看>>
对Delphi 7/Delphi 2007的Windows服务类库的一个小改进
查看>>