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 ...
随机推荐
- openstack命令行
openstack的每一个子项目(project)都有自己对应的命令行API,所有的这些API都是基于RESTful的,python代码实现的API.也就是说,这些API都是基于HTTP实现的,所以A ...
- HTML5跨浏览器表单及HTML5表单的渐进增强
HTML5跨浏览器表单 http://net.tutsplus.com/tutorials/html-css-techniques/how-to-build-cross-browser-html5-f ...
- 阿里云Mysql重置密码
1.关闭mysql服务 # service mysql stop 如果提示mysql: unrecognized service这样的错误提示. 先查看查找mysql.server,使用:find / ...
- 安卓集成发布详解(二)gradle
转自:http://frank-zhu.github.io/android/2015/06/15/android-release_app_build_gradle/ 安卓集成发布详解(二) 15 Ju ...
- js实现windows扫雷(jquery)
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- MySQL运行出错:无法连接驱动、无root访问权限解决办法
按照疯狂java讲义的13.3的程序,发现程序运行出错. 1.点开runConnMySql.cmd运行文件,出现如下结果: 2.用Editplus进行编译运行,如下结果: 报错定位到程序第18行,而第 ...
- shell下root用户切换其他用户运行程序
工作中,一些程序,需要随机启动,但是不是以root用户运行,于是需要在rc.local中通过shell,从root用户切换到其他用户运行程序,命令如下: su -c 'command' - user ...
- POJ 2411 Mondriaan'sDream(状压DP)
题目大意:一个矩阵,只能放1*2的木块,问将这个矩阵完全覆盖的不同放法有多少种. 解析:如果是横着的就定义11,如果竖着的定义为竖着的01,这样按行dp只需要考虑两件事儿,当前行&上一行,是不 ...
- CF478 B. Random Teams 组合数学 简单题
n participants of the competition were split into m teams in some manner so that each team has at le ...
- vs2015-Azure Mobile Service
/App_Data /App_Start/ WebApiConfig.cs using System; using System.Collections.Generic; using System.C ...