A
就是简单的数学题,唯一注意的就是精度问题exp(1)算出来的是e的准确值,exp(x)返回e的x次方,之后跟着题意写全代码就行。
中途想到了一下二分快速幂,发现pow()就是浮点型的,直接拿来用了,顺变补个快速幂吧,大数的,矩阵快速幂回头再补。
#include<bits/stdc++.h>
using namespace std;
#define e exp(1)
int main(){
int t;
cin>>t;
double a,b,c;
while(t--){
scanf("%lf%lf%lf",&a,&b,&c);
cout<<fixed<<setprecision(c);
double ans=(pow(e,a))*b;
cout<<ans<<endl;
}
return 0;
}
#define ll long long
ll poww(ll a,ll b){
ll ans=1,base=a;
while(b){
if(b&1) ans*=base;
base*=base;
b>>=1;
}
return ans;
}
B
和A一模一样
#include<bits/stdc++.h>
using namespace std;
#define e exp(1)
int main(){
int t;
cin>>t;
double a,b,c;
while(t--){
scanf("%lf%lf%lf",&a,&b,&c);
double ans=pow(a,e)/b;
cout<<fixed<<setprecision(c)<<ans<<endl;
}
return 0;
}
C
额,和前两个题一样一样的。有点小弯弯,读明白了题之后就好了。
就是a个馅,b个皮,c个桌子,d个碗。馅和皮组成种类,桌子和碗组成总共碗的数量。而每一个碗都可以填ab种,有cd个碗,所以答案显而易见是(ab)^(cd)。
和前两个题不同新增了一个取模。然后又有:(ab)%mod=((a%mod)(b%mod))%mod。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll poww(ll a,ll b,ll mod){
ll ans=1;
if(b==0) return 0;
while(b){
if(b&1) ans=ans*a%mod;
a=a*a%mod;
b>>=1;
}
return ans;
}
int main(){
ll a,b,c,d,e;
cin>>a>>b>>c>>d>>e;
cout<<poww(((a%e)*(b%e))%e,c*d,e);
return 0;
}
D
最简单的双循环就给过了
注意一下最后一个数后面没有空格
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[505],b[505];
int num[505*2];
int main(){
int n,m;
cin>>n>>m;
for(int i=0;i<=n;i++) cin>>a[i];
for(int i=0;i<=m;i++) cin>>b[i];
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
num[i+j]+=a[i]*b[j];
}
}
for(int i=0;i<n+m+1;i++){
if(i==n+m) cout<<num[i];
else cout<<num[i]<<" ";
}
return 0;
}
E
三角函数化简
#include<bits/stdc++.h>
using namespace std;
int main(){
double r;
cin>>r;
cout<<fixed<<setprecision(2);
cout<<r+1;
return 0;
}
F
直接模拟
#include<bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
bool x[N][N];
bool y[N][N];
bool z[N][N];
int main(){
int X,Y,Z,n;
scanf("%d%d%d%d",&X,&Y,&Z,&n);
while(n--){
int tx,ty,tz;
scanf("%d%d%d",&tx,&ty,&tz);
x[ty][tz] = true;
y[tz][tx] = true;
z[tx][ty] = true;
}
for(int i = Y;i >= 1;i--){
for(int j = 1;j <= X;j++){
putchar(z[j][i] ? 'x' : '.');
}
putchar(' ');
for(int j = 1;j <= Z;j++){
putchar(x[i][j] ? 'x' : '.');
}
putchar('\n');
}
printf("\n");
for(int i = 1;i <= Z;i++){
for(int j = 1;j <= X;j++){
putchar(y[i][j] ? 'x' : '.');
}
putchar('\n');
}
return 0;
}
剩下的几道回头再补