如題,在第一個測資為AC,為何第二個測資點是WA(line:1)?
您的答案為:65
正確答案為:50
我的程式碼如下:
#include<iostream>
#include<cmath>
using namespace std;
void shellSort(int numbers[], int array_size)
{
int i, j, increment, temp;
increment = 3;
while (increment > 0)
{
for (i=0; i < array_size; i++)
{
j = i;
temp = numbers[i];
while ((j >= increment) && (numbers[j-increment] < temp))
{
numbers[j] = numbers[j - increment];
j = j - increment;
}
numbers[j] = temp;
}
if (increment/2 != 0)
increment = increment/2;
else if (increment == 1)
increment = 0;
else
increment = 1;
}
}
int main()
{
int b[10000],a,c;
while(cin>>a){
int w=0;
for(int i=0;i<a;i++){
cin>>c;
for(int j=0;j<c;j++){
cin>>b[j];
}
shellSort(b,c);
cout<<b[(c)/2]<<endl;
}
}
return 0;
}
如題,在第一個測資為AC,為何第二個測資點是WA(line:1)?
您的答案為:65
正確答案為:50
我的程式碼如下:
#include
#include
using namespace std;
void shellSort(int numbers[], int array_size)
{
int i, j, increment, temp;
increment = 3;
while (increment > 0)
{
for (i=0; i < array_size; i++)
{
j = i;
temp = numbers[i];
while ((j >= increment) && (numbers[j-increment] < temp))
{
numbers[j] = numbers[j - increment];
j = j - increment;
}
numbers[j] = temp;
}
if (increment/2 != 0)
increment = increment/2;
else if (increment == 1)
increment = 0;
else
increment = 1;
}
}
int main()
{
int b[10000],a,c;
while(cin>>a){
int w=0;
for(int i=0;i
cin>>c;
for(int j=0;j
cin>>b[j];
}
shellSort(b,c);
cout<<
}
}
return 0;
}
元素最多40000個
可是陣列你只設10000
我剛改40000去跑, 結果TLE
請想不用排序的方法