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

本文共 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

你可能感兴趣的文章
创建自己的awaitable类型
查看>>
Wildcard Matching
查看>>
一件小事测试各个搜索引擎:谷歌、bing、有道、百度、搜狗、360
查看>>
JAX-RS 2.0 草案发布,新特性一览
查看>>
OpenCV 2.4.3 发布,开源计算机视觉库
查看>>
第49周星期四
查看>>
二叉搜索树转双向链表
查看>>
【电信增值业务学习笔记】11 基于Parlay的增值业务提供技术
查看>>
用“分支判断”来为程序“解套”
查看>>
ubuntu Linux下DHCP的配置
查看>>
新塘连接
查看>>
Vim删除重复行
查看>>
预处理语句
查看>>
2012第52周五阴小雨
查看>>
滚动双联广告
查看>>
linux sort,uniq,cut,wc命令详解
查看>>
纯CSS和Javascript实现的遮罩层
查看>>
python类型转换、数值操作
查看>>
关于Scalability的一些思考与疑问
查看>>
mongodb step by step
查看>>