CSP2022-06
第一题
水题,没啥好说的
#include <iostream> #include <cmath> using namespace std; const int N = 1e6 ; double a[N] ; int main(){ int n ; cin>>n ; double sum = 0; for(int i=0; i<n; i++ ) { cin>>a[i]; sum += a[i] ; } double ave = sum / n ; double Da = 0 ; for(int i=0; i<n; i++) { Da += (a[i]-ave) * (a[i]-ave) / n ; } for(int i=0; i<n; i++) { printf("%f\n", (a[i]-ave)/sqrt(Da)) ; } return 0 ; }
第二题
看的出来是图的动态规划,还没学这里,直接暴力弄了,70分
#include <iostream> #include <cmath> using namespace std; const int N = 3e3 ; int a[N][N], b[N][N] ; int n,l,s ; int main(){ cin>>n>>l>>s; int x1,y1 ; for(int i=1; i<=n; i++ ) { cin>>x1>>y1; a[x1][y1] = 1 ; // 绿化 } for(int i=s; i>=0; i--) for(int j=0; j<=s ;j++) cin>> b[i][j]; //藏宝 int cnt = 0; for(int i=0; i<=l; i++) for(int j=0; j<=l; j++) { bool flag = false ; if(a[i][j] == 1) //找到树,比较藏宝图 { flag = true ; // 首先要找到,期望是true for(int x = 0, xx=i; x<=s; x++,xx++ ) for(int y = 0, yy=j; y<=s ; y++, yy++) { if(xx>l || yy>l) { flag = false; goto exit_ ; // 超出边界 } if( a[xx][yy] != b[x][y] ) { flag = false; goto exit_; } } } exit_: if (flag) cnt++; } cout<<cnt ; return 0 ; }