纯模拟
2026-02-09 19:25:11
发布于:四川
14阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
const int N = 100+10;
int a[N];
int n;
int check(){
int s= 0, j;
for(j = 0; j < n; j++){
if(a[j]!=0){
return 1;
}
}
return 0;
}
int main(){
int i, j, step = 0;
int s = 0;
cin >> n;
for(i = 0; i < n; i++){
cin >> a[i];
if(a[i] != 0)s++;
}
while(s!=0){
//找到最{大值,和下标
int mx = -2e9, mx_i;
for(j = 0; j < n; j++){
if(mx < a[j]){
mx = a[j];
mx_i = j;
}
}
//mx mx_i;
int mi = 2e9;
for(j = 0; j < n; j++){
if(a[j] != 0 && a[j] < mi){
mi = a[j];
}
}
a[mx_i] = a[mx_i] - mi;
if(a[mx_i] == 0)s--;
step++;
}
cout << step;
return 0;
}
这里空空如也







有帮助,赞一个