先排序,比较各段最大的,为啥不通过呢?本地都好使啊
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
int xiaomei;
vector<int>arr;
for (int i = 0; i < n; i++)
{
cin >> xiaomei;
arr.push_back(xiaomei);
}
xiaomei = arr[0];
sort(arr.begin() + 1, arr.end());
int cishu = 0;
for (int i = 1,j=2; i < n-1; )
{
if (xiaomei >= arr[i])
{
cishu++;
i =(int)pow(2.0,(double)j)-1;
j++;
}
else
break;
}
cout << cishu+1;
}
cout << endl;
return 0;
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
int xiaomei;
vector<int>arr;
for (int i = 0; i < n; i++)
{
cin >> xiaomei;
arr.push_back(xiaomei);
}
xiaomei = arr[0];
sort(arr.begin() + 1, arr.end());
int cishu = 0;
for (int i = 1,j=2; i < n-1; )
{
if (xiaomei >= arr[i])
{
cishu++;
i =(int)pow(2.0,(double)j)-1;
j++;
}
else
break;
}
cout << cishu+1;
}
cout << endl;
return 0;
}
请问一下,这段代码错在哪里呢?