HDU - 3521 An easy Problem(矩阵快速幂)
http://acm.hdu.edu.cn/showproblem.php?pid=3521
题意
对于矩阵A,求e^A的值。
分析
这个定眼一看好像很熟悉,就是泰勒展开,可惜自己的高数已经还给老师了。。。比赛时不敢直接暴力写,实际上循环到一定次数,余式对结果的影响就相当小了。循环到50几次就可以了
#include<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio>
#include<algorithm>
#include<map>
#include<set>
#define rep(i,e) for(int i=0;i<(e);i++)
#define rep1(i,e) for(int i=1;i<=(e);i++)
#define repx(i,x,e) for(int i=(x);i<=(e);i++)
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define mset(var,val) memset(var,val,sizeof(var))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pd(a) printf("%d\n",a)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld%lld",&a,&b)
#define sclll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define IOS ios::sync_with_stdio(false);cin.tie(0) using namespace std;
typedef long long ll;
template <class T>
void test(T a){cout<<a<<endl;}
template <class T,class T2>
void test(T a,T2 b){cout<<a<<" "<<b<<endl;}
template <class T,class T2,class T3>
void test(T a,T2 b,T3 c){cout<<a<<" "<<b<<" "<<c<<endl;}
const int N = 1e6+;
//const int MAXN = 210;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const ll mod = ;
int T;
void testcase(){
printf("Case #%d: ",++T);
}
const int MAXN = ;
const int MAXM = ; struct matrix{
double ma[MAXN][MAXN];
}x,y,temp; int n;
matrix multi(matrix a,matrix b){
matrix c;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
c.ma[i][j]=;
for(int k=;k<=n;k++){
c.ma[i][j]+=a.ma[i][k]*b.ma[k][j]; }
}
}
return c;
} double P[];
void init(){
P[]=1.0;
for(int i=;i<;i++){
P[i]=i*P[i-];
}
}
void power(int exp){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
temp.ma[i][j]=;
y.ma[i][j]=x.ma[i][j];
}
temp.ma[i][i]=;
}
while(exp){
if(exp&){
temp=multi(temp,y);
}
exp>>=;
y=multi(y,y);
}
}
int main() {
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
matrix ans;
init();
while(~scd(n)&&n){
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
scanf("%lf",&x.ma[i][j]);
ans.ma[i][j]=;
}
}
for(int i=;i<;i++){
power(i);
for(int j=;j<=n;j++){
for(int k=;k<=n;k++){
ans.ma[j][k]+=(temp.ma[j][k]/P[i]);
}
}
} for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
printf("%.2f ",ans.ma[i][j]);
}
puts("");
}
}
return ;
}
HDU - 3521 An easy Problem(矩阵快速幂)的更多相关文章
- hdu 4565 So Easy!(矩阵+快速幂)
题目大意:就是给出a,b,n,m:让你求s(n); 解题思路:因为n很可能很大,所以一步一步的乘肯定会超时,我建议看代码之前,先看一下快速幂和矩阵快速幂,这样看起来就比较容易,这里我直接贴别人的推导, ...
- hdu 5667 BestCoder Round #80 矩阵快速幂
Sequence Accepts: 59 Submissions: 650 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- HDU 1757 A Simple Math Problem (矩阵快速幂)
题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...
- HDU1757 A Simple Math Problem 矩阵快速幂
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 4686 Arc of Dream(矩阵快速幂)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 其中a0 = A0ai = ai-1*AX+AYb0 = B0bi = bi-1*BX+BY ...
- HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1
http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...
- HDU 4990 Reading comprehension 简单矩阵快速幂
Problem Description Read the program below carefully then answer the question.#pragma comment(linker ...
- [hdu 2604] Queuing 递推 矩阵快速幂
Problem Description Queues and Priority Queues are data structures which are known to most computer ...
- HDU - 4990 Reading comprehension 【矩阵快速幂】
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4990 题意 初始的ans = 0 给出 n, m for i in 1 -> n 如果 i 为奇 ...
随机推荐
- Nginx rewrite模块深入浅出详解
rewrite模块(ngx_http_rewrite_module) nginx通过ngx_http_rewrite_module模块支持url重写.支持if条件判断,但不支持else.另外该模块需要 ...
- Jfrog Artifactory jenkins 流水线使用docker的方式培训[暂未成功]
1. 创建jenkins的流水线 2. 创建artifactory的镜像仓库 3. 创建generic的仓库上传需要的 war包还有tar包. 4. 修改pipeline的 脚本 主要修改的地方. 修 ...
- [日常工作]虚拟机或者实体机转换成HyperV虚拟机的方法
1.环境种类比较多, 有vb的 vm的还有人想直接用hyperV的 毕竟docker 是一个趋势, win10 上面 安装了hyperV 启用docker 角色之后 安装vb和vm的话 就没法启用CP ...
- CnPack实用功能推荐
已经使用CnPack好几年了,这个插件太好了,现在离开它我都不会写代码了,现在将使用心得与大家分享一下: 1.代码助手非常好用,只需要输入几个字符后,自动出现提示列表,真是懒人的福音呀. 2.代码高亮 ...
- html 头部 head
head里面包含标签有: title:html名称,每个html文档都必须有 形式:<title>名字</title>,文档区不显示,浏览器可以识别: 浏览器工具栏显示的页面标 ...
- maven 聚合的含义是父类打包 ,清理等 则子类自动打包;也就是一键打包 方便服务
maven 聚合的含义是父类打包 ,清理等 则子类自动打包:也就是一键打包 方便服务
- 浅谈教你如何掌握Linux系统
linux能做什么?相信绝大数人都有这样的疑问.可以玩吃鸡吗?可以玩lol吗? 如果你是以娱乐的名义来评价linux的可用性,对不起,linux可能不适合你,因为linux是一个工具,他是教你聪明的, ...
- MySQL Binlog详解
MySQL Binlog详解 Mysql的binlog日志作用是用来记录mysql内部增删改查等对mysql数据库有更新的内容的记录(对数据库的改动),对数据库的查询select或show等不会被bi ...
- BZOJ3322[Scoi2013]摩托车交易——最大生成树+贪心+倍增
题目描述 mzry1992 在打完吊针出院之后,买了辆新摩托车,开始了在周边城市的黄金运送生意.在mzry1992 生活的地方,城市之间是用双向高速公路连接的.另外,每条高速公路有一个载重上限,即在不 ...
- BZOJ2863[SHOI2012]魔法树——树链剖分+线段树
题目描述 输入 输出 样例输入 4 0 1 1 2 2 3 4 Add 1 3 1 Query 0 Query 1 Query 2 样例输出 3 3 2 树链剖分模板题,路径修改子树查询,注意节点 ...