HDU - 6395:Sequence (分块+矩阵)
题面太丑了,就不复制了。
题意:F1=A; F2=B; Fn=D*Fn-1+C*Fn-2+P/i;求Fn。
思路:根据P/i的值划分区间,每个区间矩阵求。
带常数的矩阵:
- #include<bits/stdc++.h>
- #define ll long long
- #define rep(i,a,b) for(int i=a;i<=b;i++)
- using namespace std;
- const int Mod=1e9+;
- struct mat
- {
- int mp[][];
- mat(){memset(mp,,sizeof(mp)); }
- mat friend operator *(mat a,mat b)
- {
- mat res;
- rep(k,,) rep(i,,) rep(j,,)
- res.mp[i][j]=(res.mp[i][j]+((ll)a.mp[i][k]*b.mp[k][j]%Mod))%Mod;
- return res;
- }
- mat friend operator ^(mat a,int x)
- {
- mat res;
- rep(i,,) res.mp[i][i]=;
- while(x){
- if(x&) res=res*a; a=a*a; x>>=;
- }return res;
- }
- };
- int main()
- {
- int T,N,A,B,C,D,P,fcy;
- scanf("%d",&T);
- while(T--){
- scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&P,&N);
- if(N==) {printf("%d",A); continue;}
- if(N==) {printf("%d",B); continue;}
- for(int i=,r;i<=N;i=r+){
- int tmp=P/i;
- if(tmp==) r=N;
- else r=min(P/(P/i),N);
- mat ans,base;
- ans.mp[][]=B;ans.mp[][]=A; ans.mp[][]=;
- base.mp[][]=D; base.mp[][]=C; base.mp[][]=tmp;
- base.mp[][]=base.mp[][]=;
- ans=(base^(r-i+))*ans;
- if(r==N) fcy=ans.mp[][];
- else B=ans.mp[][],A=ans.mp[][];
- }
- printf("%d\n",fcy);
- }
- return ;
- }
HDU - 6395:Sequence (分块+矩阵)的更多相关文章
- HDU 6395 Sequence 【矩阵快速幂 && 暴力】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others) ...
- HDU - 6395 Sequence (分块+快速矩阵幂)
给定递推式: 求Fn. 分析:给出的公式可以用快速矩阵幂运算得到,但 P/n 整除对于不同的i,值是不同的. 可以根据P将3-n分成若干块,每块中P整除n的值是相同的.分块的时候要注意判断. 将每块的 ...
- HDU - 6395 Sequence (整除分块+矩阵快速幂)
定义数列: $\left\{\begin{eqnarray*} F_1 &=& A \\ F_2 &=& B \\ F_n &=& C\cdot{}F_ ...
- HDU 6395 Sequence(分段矩阵快速幂)题解
题意: 已知\(A,B,C,D,P,n\)以及 \[\left\{ \begin{aligned} & F_1 = A \\ & F_2 = B\\ & F_n = C*F_{ ...
- [hdu-6395]Sequence 分块+矩阵快速幂
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6395 因为题目数据范围太大,又存在递推关系,用矩阵快速幂来加快递推. 每一项递推时 加的下取整的数随 ...
- HDU 5667 Sequence(矩阵快速幂)
Problem Description Holion August will eat every thing he has found. Now there are many foods,but he ...
- HDU 5667 Sequence【矩阵快速幂+费马小定理】
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5667 题意: Lcomyn 是个很厉害的选手,除了喜欢写17kb+的代码题,偶尔还会写数学题.他找到 ...
- HDU 6395 Sequence 杜教板子题
题目意思非常明确,就是叫你求第n项,据我们学校一个大佬说他推出了矩阵,但是我是菜鸡,那么肯定是用简单的方法水过啦!我们先p^(1/2)的复杂度处理出i=[i,p]范围内的所有种类的(int)(p/i) ...
- hdu 6395 Sequence (简单矩乘)
P/n大多数情况是不变的, 取值只有$O(\sqrt{P})$种, 可以用$p/(p/i)$跳过重复的值, 复杂度$O(logn\sqrt{P})$ 要注意 P跟模数P有冲突 要特判p/i==0和p/ ...
- Sequence( 分块+矩阵快速幂 )
题目链接 #include<bits/stdc++.h> using namespace std; #define e exp(1) #define pi acos(-1) #define ...
随机推荐
- webform中Repeater的Command用法、Repeater的替代方法
Command: 在Repeater控件循环执行过程中,可以给每一项的某个按钮或其他控件设置CommandName.CommandArgument属性,用于在后台代码中获取单项 数据进行调用. 需 ...
- Web开发相关笔记
1.MySQL命令行下执行.sql脚本详解http://database.51cto.com/art/201107/277687.htm 在可视化工具里导出.sql脚本 --> 放命令行里运行 ...
- 配置OpenVpn使用证书和用户名密码双验证
修改OpenVpn的主配置文件 添加一下内容: [root@check1 openvpn]# tail -3 server.conf auth-user-pass-verify /etc/openvp ...
- Spring_事务准备
- nginx反向代理服务器端口问题
nginx可以很方便的配置成反向代理服务器 server { listen 80; server_name bothlog.com; location / { proxy_set_header H ...
- LeetCode——Construct the Rectangle
LeetCode--Construct the Rectangle Question For a web developer, it is very important to know how to ...
- 低版本C++ string的万能转换,从long string 之间的转换来看看
string 转 long 那必须是万年atoi(),不过得配合c_str()使用! [plain] view plain copy #include <string> #include ...
- QTableWidget 列排序
connect(uirecord.tableWidget->horizontalHeader(),SIGNAL(sectionClicked(int)),this,SLOT(record_sor ...
- JavaWeb -- Struts1 使用示例: 表单校验 防表单重复提交 表单数据封装到实体
1. struts 工作流程图 超链接 2. 入门案例 struts入门案例: 1.写一个注册页面,把请求交给 struts处理 <form action="${pageContext ...
- Codeforces Round #363 (Div. 2) A、B、C
A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...