雅礼集训D1T3 math [咕咕咕]
Posted p-b-p-b
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了雅礼集训D1T3 math [咕咕咕]相关的知识,希望对你有一定的参考价值。
题目描述:
样例:
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
",(int)(s/s1));break;}else s1*=0.1;
}else{
while (s)if (s<10) {printf("%d
",(int)s);break;}else s/=10;
}
}
}
以上是关于雅礼集训D1T3 math [咕咕咕]的主要内容,如果未能解决你的问题,请参考以下文章