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(矩阵快速幂)的更多相关文章

  1. hdu 4565 So Easy!(矩阵+快速幂)

    题目大意:就是给出a,b,n,m:让你求s(n); 解题思路:因为n很可能很大,所以一步一步的乘肯定会超时,我建议看代码之前,先看一下快速幂和矩阵快速幂,这样看起来就比较容易,这里我直接贴别人的推导, ...

  2. hdu 5667 BestCoder Round #80 矩阵快速幂

    Sequence  Accepts: 59  Submissions: 650  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536 ...

  3. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  4. HDU1757 A Simple Math Problem 矩阵快速幂

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. 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 ...

  6. HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...

  7. HDU 4990 Reading comprehension 简单矩阵快速幂

    Problem Description Read the program below carefully then answer the question.#pragma comment(linker ...

  8. [hdu 2604] Queuing 递推 矩阵快速幂

    Problem Description Queues and Priority Queues are data structures which are known to most computer ...

  9. HDU - 4990 Reading comprehension 【矩阵快速幂】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4990 题意 初始的ans = 0 给出 n, m for i in 1 -> n 如果 i 为奇 ...

随机推荐

  1. Java使用HTTPClient4.3开发的公众平台消息模板的推送功能

    代码引用,参考文章:http://www.cnblogs.com/feiyun126/p/4778556.html,表示感谢! package com.yuanchuangyun.cyb.manage ...

  2. 虚拟机使用不同CPU配置时内存性能的差异

    第一款机器的配置: CPU(s): 8On-line CPU(s) list: 0-7Thread(s) per core: 1Core(s) per socket: 4座: 2NUMA 节点: 1 ...

  3. js history

    後退:退到歷史列表的前一個url,和瀏覽器點擊後退按鈕功能相同 history.back() 前進:進入歷史列表的後面一個url,和瀏覽器的前進按鈕功能相同 history.forward()

  4. js Location

    window.location用來返回頁面的地址,并把頁面重定向新的頁面: location.pathname:返回當前的頁面地址和文件名 location.hostname:主機名 location ...

  5. js語句

    js語句就是告訴瀏覽器要做什麼: js代碼就是js語句序列: js代碼塊就是{}包括的,函數就是一個代碼塊的典型例子: js注釋:單行注釋://,多行注釋:/**/ js對大小寫敏感: js語句可以不 ...

  6. Java之枚举举例

    package enumdemo; /** * 枚举类 */ public enum MAPPER { // 实例 ELEMENT_NAME("mapper"), ATTRIBUT ...

  7. ThinkPHP 框架出现安全隐患 ,导致网站被持续攻击一周

    导读 据 ZDNET 报道,有超过 45000 个中国网站由于使用 ThinkPHP 框架受到了攻击. 这些攻击针对的是使用 ThinkPHP 构建的网站,ThinkPHP 是一个中国的 PHP 框架 ...

  8. python----内置函数2与匿名函数

    1.迭代器生成器相关 range:创建一个可迭代对象,一般与for混合使用,可设置步长. for i in range(0,10,2): #步长2范围为0-10不包括10 print(i) # 0 2 ...

  9. asp.net 后台<%@ Page%> page指令属性

    aspx文件有如下一行代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind=" ...

  10. BZOJ2124 等差子序列(树状数组+哈希)

    容易想到一种暴力的做法:枚举中间的位置,设该位置权值为x,如果其两边存在权值关于x对称即合法. 问题是如何快速寻找这个东西是否存在.考虑仅将该位置左边出现的权值标1.那么若在值域上若关于x对称的两权值 ...