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= ;
const LL Mod= ;
LL A[M] ;
struct Mat{
LL num[][] ;
Mat(){} ;
Mat(int a11 ,int a12 ,int a21 ,int a22){
num[][]=a11 ;
num[][]=a12 ;
num[][]=a21 ;
num[][]=a22 ;
}
Mat operator *(Mat &B){
Mat ans(,,,) ;
for(int i= ;i<= ;i++)
for(int j=;j<= ;j++)
for(int k=;k<=; 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(,,,) ;
for(;y;y>>=){
if(y&)
ans=ans*X ;
X=X*X ;
}
return ans ;
}
LL a[] ;
int main(){
LL N ,K ,L ;
while(cin>>N>>K>>L){
N/= ;
Mat A(K%Mod ,L%Mod , ,) ;
a[]=K%Mod ;
a[]=(((K%Mod)*(K%Mod))%Mod+L%Mod)%Mod ;
if(N==)
printf("%06d\n",(int)a[]) ;
else if(N==)
printf("%06d\n",(int)a[]) ;
else{
A=Pow(A,N-) ;
LL ans=(A.num[][]*a[]%Mod+A.num[][]*a[]%Mod)%Mod ;
printf("%06d\n",(int)ans) ;
}
}
return ;
}
UVA12653 Buses的更多相关文章
- CF459C Pashmak and Buses (构造d位k进制数
C - Pashmak and Buses Codeforces Round #261 (Div. 2) C. Pashmak and Buses time limit per test 1 seco ...
- codeforces 459C Pashmak and Buses 解题报告
题目链接:http://codeforces.com/problemset/problem/459/C 题目意思:有 n 个 students,k 辆 buses.问是否能对 n 个students安 ...
- ural 1434. Buses in Vasyuki
1434. Buses in Vasyuki Time limit: 3.0 secondMemory limit: 64 MB The Vasyuki University is holding a ...
- cf459C Pashmak and Buses
C. Pashmak and Buses time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces #261 C题 Pashmak and Buses(瞎搞)
题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...
- Problem J: Island Buses
主要题意是:大海之间有岛,有的岛之间有桥,问你岛的个数,桥的个数,以及没有桥联通岛的个数,其中最后一次输入的没有回车,不注意的话最后一次会被吞,第二,桥的两端的标记是“X”(X也代表陆地),“X”的四 ...
- Codeforces 665A. Buses Between Cities 模拟
A. Buses Between Cities time limit per test: 1 second memory limit per test: 256 megabytes input: s ...
- Educational Codeforces Round 12 A. Buses Between Cities 水题
A. Buses Between Cities 题目连接: http://www.codeforces.com/contest/665/problem/A Description Buses run ...
- cf 459c Pashmak and Buses
E - Pashmak and Buses Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
随机推荐
- Ext JS4 学习笔记之发送表单(Form)时也将表单下的表格(Grid)数据一同发送的方法
Ext JS4 学习笔记之发送表单(Form)时也将表单下的表格(Grid)数据一同发送的方法 昨天在开发的时候遇到个小问题,就是如何将Grid的内容与Form一起发送到服务器端.默认情况下,表单(F ...
- 【shell】通配符
‘’与“” [root@andon ~]# name='$date' [root@andon ~]# echo $name $date [root@andon ~]# name=abc [root@a ...
- Redis 宣言(Redis Manifesto)
Redis 的作者 antirez(Salvatore Sanfilippo)曾经发表了一篇名为 Redis 宣言(Redis Manifesto)的文章,文中列举了 Redis 的七个原则,以向大家 ...
- IntelliJ IDEA手动配置连接MySQL数据库
先从菜单View→Tool Windows→Database打开数据库工具窗口,如下图所示: 点击Database工具窗口左上角添加按钮"+",选择数据库类型,这里以MySQL为例 ...
- [linux basic 基础]----同步信号量
直接使用一个共享变量,来是两个线程之间进行切换是非常笨拙而且没有效率的:信号量--互斥量--这两者是相互通过对方来实现的:比如,如果想控制某一时刻只有一个线程可以访问一些共享内存,使用互斥量要自然一些 ...
- MySQL优化—工欲善其事,必先利其器之EXPLAIN
最近慢慢接触MySQL,了解如何优化它也迫在眉睫了,话说工欲善其事,必先利其器.最近我就打算了解下几个优化MySQL中经常用到的工具.今天就简单介绍下EXPLAIN. 内容导航 id select_t ...
- Java-螺旋方阵
用Java实现螺旋方阵 螺旋方阵:是指呈螺旋状的矩阵. 具体实现如下: public void screwMatrix() { System.out.print("请输入数字:") ...
- 黄聪:怎么清理win7、win8更新垃圾(winsxs目录清理)
windows 系统(特别是Win8系统)在使用了一段时间后,发现C盘的空间降的好厉害,显然,有大量不该存在的文件还继续停留在硬盘里.究其原因,在于系统目录下的WinSxS目录占用了大量的空间!在我们 ...
- eclipse 每次切换工作空间都要重新配置
首先,导出T1中的配置打开T1,选择file --> Export --> 在弹出框中选择General 下的preference --> next --> 在export p ...
- python3-cookbook
http://python3-cookbook.readthedocs.io/zh_CN/latest/index.html 一般的类找方法,通过MRO找到第一个就停了对吧,可以描述器好像会顺着MRO ...