标签:main inpu scanf return algo stdout break mat image
题目描述:
样例:
input:
2
3 5 0.01
3 6 0.02
output:
+2
+4
数据范围:
标签: 数学,矩阵乘法
题解:
标程:
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define fo(i,a,b) for(i=a;i<=b;i++)
const int maxn=60+5;
int i,j,n,m,t,k;
struct ar{
double a[maxn][maxn];
} a,c;
double x;
ar ch(ar a,ar b){
ar c;
memset(c.a,0,sizeof(c.a));
fo(i,1,m*2)
fo(j,1,m*2)
fo(k,1,m*2) c.a[i][j]=c.a[i][j]+a.a[i][k]*b.a[k][j];
return c;
}
int main(){
freopen("math.in","r",stdin);freopen("math.out","w",stdout);
scanf("%d",&t);
while (t){
t--;
scanf("%d%d%lf",&m,&n,&x);
memset(a.a,0,sizeof(a.a));
memset(c.a,0,sizeof(c.a));
fo(i,m+1,m*2){
a.a[i][i-m]=1,a.a[i-m][i]=-1;
a.a[i][i]=2*cos(x);if (i<m*2)a.a[i][i+1]=sin(x);
}
c.a[1][1]=sin(x);c.a[1][m+1]=sin(2*x);c.a[1][m+2]=sin(x)*sin(x);
n--;
while (n){
if (n%2)c=ch(c,a);
a=ch(a,a);
n/=2;
}
double s=c.a[1][m];
if (s>0) printf("+");else printf("-");
s=fabs(s);
if (s<1){
double s1=0.1;
while (1) if (s>s1) {printf("%d\n",(int)(s/s1));break;}else s1*=0.1;
}else{
while (s)if (s<10) {printf("%d\n",(int)s);break;}else s/=10;
}
}
}
标签:main inpu scanf return algo stdout break mat image
原文地址:https://www.cnblogs.com/p-b-p-b/p/10229850.html