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 为奇 ...
随机推荐
- PAT 1037 在霍格沃茨找零钱
https://pintia.cn/problem-sets/994805260223102976/problems/994805284923359232 如果你是哈利·波特迷,你会知道魔法世界有它自 ...
- Spring事务银行转账示例
https://www.imooc.com/video/9331 声明式事务 @Transactiona() 编程式事务 非模板式(不使用TransactionTemplate) http://cai ...
- Docker for windows 入门三(PowerShell命令使用)
- ECSHOP广告调用广告位添加到首页顶部通栏教程
ECSHOP广告调用广告位添加到首页顶部通栏教程 ECSHOP教程/ ecshop教程网(www.ecshop119.com) 2012-05-26 ECSHOP系统默认预留的广告位很少,如何才能 ...
- [转帖] securebootthemes 挖矿病毒的说明 http://blog.netlab.360.com/msraminer-qian-fu-yi-jiu-de-wa-kuang-jiang-shi-wang-luo/ 原文为毛不给一个专杀工具呢.
MsraMiner: 潜伏已久的挖矿僵尸网络 2017 年 11 月底,我们的 DNSMon 系统监测到几个疑似 DGA 产生的恶意域名活动有异常.经过我们深入分析,确认这背后是一个从 2017 年 ...
- windows下git显示文件被修改,实际没有改动的问题解决办法
不少开发者可能遇到过这个问题:从git上拉取服务端代码,然后只修改了一处地方,准备提交时,用diff软件查看,却发现整个文件都被修改了.这是git自动转换换行符导致的问题. 原因 不同操作系统使用的换 ...
- QA
QA:Quality Assurance,品质保证 IDQA:Individual Document Quality Assurance 设计品质保证 QE:Quantitative Easing 质 ...
- 配置自己的Maven方式并使用Maven 运行项目Idea的maven的项目
(1) 当安装了 maven之后,需要导入项目代码,然后编译执行: 打开Idea ==>然后点击小扳手==>在搜索框中输入maven==>然后找到 Maven home direct ...
- matplotlib之scatter自动绘制散点
# 使用matplotlib.pyplot.scatter绘制散点 import matplotlib.pyplot as plt from pylab import mpl # 设置默认字体,解决中 ...
- String在内存中如何存储(Java)
JDK1.8中JVM把String常量池移入了堆中,同时取消了“永久代”,改用元空间代替(Metaspace)java中对String对象特殊对待,所以在heap区域分成了两块,一块是字符串常量池(S ...