Title
Code
#include <iostream>
#include <algorithm>
#include <string.h>
#define size 10010
using namespace std;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
int n;
cin >> n;
int size[Maxsize];
int body[Maxsize] = { 0 };
for (int i = 0; i < n; i++) {
cin >> size[i];
}
int res = 0, size_temp = 0, box = 0; //最终盒子数,当前嵌套的盒子大小,已处理的盒子数
sort(size, size + n, cmp);
while (box < n) {
size_temp = 0;
for (int i = 0; i < n; i++) {
if (size_temp == 0 && body[i] == 0) { //该嵌套盒是否是最外层盒子
box++;
size_temp = size[i];
body[i] = 1;
}
else if (size[i] < size_temp && body[i] == 0) {
box++;
size_temp = size[i];
body[i] = 1;
}
}
res++;
}
cout << res << endl;
return 0;
}
Problem
The test pass rate is too low. I wonder what aspect is not taken into account.
0 Answer
No answer yet
这家伙很懒,什么都没留下...