完成了前面两道题,得了200分(目前只有前两题的题解,后续会补充其他题目)
题目一:归一化处理
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
//7 -4 293 0 -22 12 654 1000
//题目很简单,一步一步处理就能AC
int main()
{
int n;
double a[1005];
double D,avg;
int i,j;
cin>>n;
avg=0;
D=0;
for(i=0;i<n;i++)
{
cin>>a[i];
avg+=a[i];
}
avg=avg/n;
for(i=0;i<n;i++)
{
D+=(a[i]-avg)*(a[i]-avg);
}
D=pow(D/n,0.5);
for(i=0;i<n;i++)
{
printf("%f\n",(a[i]-avg)/D);
}
return 0;
}
题目二:寻宝!大冒险!
/*
以绿化图(Lmap)上的每一棵树为右下角
构建一个(s+1)*(s+1)的矩阵(Lmap1)
再拿这个矩阵去和藏宝图(Smap)比较,相同返回1,否则返回0
要注意的是,Lmap1的构建要和Smap的构建保持一致,还有要注意的是,每次构建Lmap1的时候要先将其置0
*/
#include <iostream>
#include<bits/stdc++.h>
/*
5 4 2
0 0
1 1
2 2
3 3
4 4
0 0 0
0 1 0
1 0 0
*/
/*
5 100 2
0 0
1 1
2 2
3 3
4 4
0 0 1
0 1 0
1 0 0
*/
using namespace std;
typedef struct
{
long x;
long y;
} Point;
Point Lmap[1005];
bool Lmap1[55][55];
bool Smap[55][55];
long n,L,S;
long sum=0;
void Set(bool Map[][55],Point p,Point *L)
{
int x=p.x;
int y=p.y;
for(int i=0;i<=S;i++)
for(int j=0;j<=S;j++)Map[i][j]=0;
for(int i=0; i<=n; i++)
{
int x1=L[i].x-x;
int y1=L[i].y-y;
if(x1>=0&&x1<=S&&y1>=0&&y1<=S)
{
Map[x1][y1]=1;
}
}
}
bool compare(bool Map[][55],bool Smap[][55])
{
for(int i=0; i<=S; i++)
{
for(int j=0; j<=S; j++)
if(Map[i][j]!=Smap[i][j])return false;
}
return true;
}
int main()
{
int i,j;
cin>>n>>L>>S;
for(i=0; i<n; i++)
{
cin>>Lmap[i].x>>Lmap[i].y;
}
for(i=S; i>=0; i--)
{
for(j=0; j<=S; j++)cin>>Smap[i][j];
}
for(i=0; i<n; i++)
{
if(Lmap[i].x+S<=L&&Lmap[i].y+S<=L)
{
Set(Lmap1,Lmap[i],Lmap);
if(compare(Lmap1,Smap))sum++;
}
}
cout<<sum;
return 0;
}