2017ACM/ICPC广西邀请赛 1004 Covering
Covering
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total
Submission(s): 0 Accepted Submission(s): 0
always play games here after school.
To protect boys and girls from
getting hurt when playing happily on the playground, rich boy Bob decided to
cover the playground using his carpets.
Meanwhile, Bob is a mean boy, so
he acquired that his carpets can not overlap one cell twice or more.
He
has infinite carpets with sizes of 1×2
and 2×1
, and the size of the playground is 4×n
.
Can you tell Bob the total number of schemes where the carpets can
cover the playground completely without overlapping?
Each
test case only contains one positive integer n in a line.
1≤n≤1018
in a line.
2
5
矩阵的算法 比赛中比较常见
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = ;
ll Matrixsize = , mod = int(1e9)+, n;
struct Matrix {
ll m[maxn][maxn];
Matrix(ll i = ) {
memset(m, , sizeof m);
if (i == )
for (ll I = ; I < Matrixsize; I++) m[I][I] = ;
}
Matrix operator * (const Matrix tmp) const {
Matrix ret;
long long x;
for(ll i= ; i<Matrixsize ; i++)
for(ll j= ; j<Matrixsize ; j++) {
x=;
for(ll k= ; k<Matrixsize ; k++)
x+=(m[i][k] * tmp.m[k][j] + mod) % mod;
ret.m[i][j] = int(x % mod);
}
return ret;
}
Matrix qpow(long long n) {
Matrix ret = , tmp = *this;
while (n > ) {
if (bool(n & )) ret = ret * tmp;
tmp = tmp * tmp;
n >>= ;
}
return ret;
}
}; int main() {
Matrix base1 = , base2 = ;
base1.m[][] = base1.m[][] = base1.m[][] = base1.m[][] = base1.m[][] = ;
base1.m[][] = -, base1.m[][] = , base2.m[][] = ;
base2.m[][] = , base2.m[][] = , base2.m[][] = ;
while(~scanf("%lld",&n)) printf("%lld\n",(base1.qpow(n)*base2).m[][]);
return ;
}
2017ACM/ICPC广西邀请赛 1004 Covering的更多相关文章
- 2017 ICPC 广西邀请赛1004 Covering
Covering Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering
Problem Description Bob's school has a big playground, boys and girls always play games here after s ...
- 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
上一场CF打到心态爆炸,这几天也没啥想干的 A Math Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3 ...
- 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi
Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...
- 2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree
Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learne ...
- 2017ACM/ICPC广西邀请赛-重现赛
HDU 6188 Duizi and Shunzi 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 思路: 签到题,以前写的. 实现代码: #inc ...
- HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序
题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...
- 2017ACM/ICPC广西邀请赛-重现赛 1001 A Math Problem
2017-08-31 16:48:00 writer:pprp 这个题比较容易,我用的是快速幂 写了一次就过了 题目如下: A Math Problem Time Limit: 2000/1000 M ...
- 2017ACM/ICPC广西邀请赛-重现赛1005 CS course
2017-08-31 16:19:30 writer:pprp 这道题快要卡死我了,队友已经告诉我思路了,但是做题速度很缓慢,很费力,想必是因为之前 的训练都是面向题解编程的缘故吧,以后不能这样了,另 ...
随机推荐
- LG4781 【模板】拉格朗日插值 和 JLOI2016 成绩比较
[模板]拉格朗日插值 题目描述 由小学知识可知,$n$个点$(x_i,y_i)$可以唯一地确定一个多项式 现在,给定$n$个点,请你确定这个多项式,并将$k$代入求值 求出的值对$998244353$ ...
- 使用selenium三种方式打开文件:
#路径读取方式一:# b.get(r"C:\我的代码\selenium自动化测试\test.html")#路径读取方式二:# b.get("C:\\我的代码\\selen ...
- C++中的类所占内存空间总结(转)
类所占内存的大小是由成员变量(静态变量除外)决定的,成员函数(这是笼统的说,后面会细说)是不计算在内的. 摘抄部分: 成员函数还是以一般的函数一样的存在.a.fun()是通过fun(a.this)来调 ...
- c#中的多态学习总结
c#的多台方法,大体上和c++的类似,但是有点区别的,我这里刚刚初学,因此把重点记录下. 多态是同一个行为具有多个不同表现形式或形态的能力. 多态性意味着有多重形式.在面向对象编程范式中,多态性往往表 ...
- hdu2643&&hdu2512——斯特林数&&贝尔数
hdu2643 题意:$n$ 个人的排名情况数($n \leq 100$) 分析:考虑 $n$ 个有区别的球放到 $m$ 个有区别的盒子里.无空盒的方案数为 $m!\cdot S(n, m)$. 这题 ...
- qtcreator cannot find catkin packages
adding /opt/ros/kinetic to CMAKE_PREFIX_PATH in Project -> build environment only /opt/ros/kineti ...
- 开源项目 10 CSV
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using Syst ...
- HAVING 搜索条件在进行分组操作之后应用
HAVING 搜索条件在进行分组操作之后应用: 如:查询帖子访问量大于15的用户id: select t.user_id,u.name,sum(count_view) from t_topic t l ...
- LG4074【WC2013】糖果公园 【树上莫队,带修莫队】
题目描述:给出一棵 \(n\) 个点的树,点有颜色 \(C_i\),长度为 \(m\) 的数组 \(V\) 和长度为 \(n\) 的数组 \(W\).有两种操作: 将 \(C_x\) 修改为 \(y\ ...
- 【AtCoder】 ARC 102
link C-Triangular Relationship 发现要么全部是\(K\)的倍数,要么全部是模\(K\)余\(K/2,(K=2n)\) #include<bits/stdc++.h& ...