- 柳泉提升班12月3日练习赛
???
- @ 2025-12-3 16:53:56
A题
#include<bits/stdc++.h>
using namespace std;
int e[10001];
int main(){
int s1,s2,s3,q=e[3],w;
cin>>s1>>s2>>s3;
for(int i=1;i<=s1;i++){
for(int j=1;j<=s2;j++){
for(int k=1;k<=s3;k++){
e[i+j+k]++;
}
}
}
for(int i=3;i<=s1+s2+s3;i++){
if(e[i]>q){
q=e[i];
w=i;
}
}
cout<<w;
}
B题
#include<bits/stdc++.h>
using namespace std;
int n,a[25][25];
int main(){
cin>>n;
for(int i=0;i<n;i++){
a[i][0]=1;
a[i][i]=1;
for(int j=1;j<i;j++){
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j<=i;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
C题
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,s[10][10],sum=0,j=0;
int a[10][10] = {0};
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
int dir = 0;
int x = 0, y = -1;
cin >> n;
for(int i=1;i<=n*n;i++){
int nx = x + dx[dir];
int ny = y + dy[dir];
if (nx >= n || ny >= n || nx < 0 || ny < 0 || a[nx][ny] != 0) {
dir = (dir + 1) % 4;
nx = x + dx[dir];
ny = y + dy[dir];
}
a[nx][ny] = i;
x = nx, y = ny;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << setw(3) << a[i][j];
}
cout << '\n';
}
}
0 comments
No comments so far...