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 ...
随机推荐
- 内容模块PC标签调用说明
内容模块 模块名:content 模块提供的可用操作 操作名 说明 lists 内容数据列表 relation 内容相关文章 hits 内容数据点击排行榜 category 内容栏目列表 positi ...
- Ruby Class
类定义: class 类名 类定义 end ※类名大写字母开始!!! 构造方法(initialize) 类名调用new方法的时候,触发的一个方法. def initialize(my_name = & ...
- 【jmeter】参数化User Defined Variables与User Parameters
偶然发现JMeter中有两个元件(User Defined Variables与User Parameters)很相近,刚开始时我也没注意,两者有什么不同.使用时却发现两者使用场景有些不同,现在小结一 ...
- 【KVM安装】在Centos6.8中安装KVM
阅读目录 前题条件 章节1:安装Centos6.8-进行硬件检测 章节2:配置网络-设置桥接方式 章节3:安装KVM 章节4:OVA转qcow2 章节5:使用KVM创建虚拟机 章节6:参考链接 前题条 ...
- read,for,case,while,if简单例子
Read多用于从某文件中取出每行进行处理 $ cat read.sh #!/bin/bash echo "using read" cat name.txt | while read ...
- TX Textcontrol 使用总结三——禁用右键、模版合并
一.Tx Textcontrol如何禁用右键快捷菜单? ==> 添加txContent_TextContextMenuOpening事件,实现方式如下所示: private void txCon ...
- haproxy实现负载均衡
一.安装tar zxvf haproxy-1.4.22.tar.gzcd haproxy-1.4.22make TARGET=linux26 PREFIX=/usr/local/haproxy ins ...
- hadoop作业调优参数整理及原理(转)
1 Map side tuning参数 1.1 MapTask运行内部原理 当map task开始运算,并产生中间数据时,其产生的中间结果并非直接就简单的写入磁盘.这中间的过程比较复杂,并且利用到了内 ...
- 多线程同步 wait notify
package test; public class Test implements Runnable{ public static int j =0; @Override public void r ...
- C#学习笔记四: C#3.0自动属性&匿名属性及扩展方法
前言 这一章算是看这本书最大的收获了, Lambda表达式让人用着屡试不爽, C#3.0可谓颠覆了我们的代码编写风格. 因为Lambda所需篇幅挺大, 所以先总结C#3.0智能编译器给我们带来的诸多好 ...