#4260: TLE (1s) == 泡沫排序


Changsunche (人外有人天外有天......現在才知道)

學校 : 不指定學校
編號 : 11725
來源 : [114.47.198.203]
最後登入時間 :
2012-01-21 07:54:44

在這裡小弟用的是泡沫排序,把數字放進陣列後,用泡沫排序將他排順序,

再取中位數......

不過方法依然是TLE.....

-------------------------------------------------------------------

請問各位方法是什麼呢!?

/**********************************************************************************/
/*  Problem: d713 "中位数" from ACM 10107 c010:What is the Median? 加强版   */
/*  Language: CPP                                                                 */
/*  Result: TLE (1)  on ZeroJudge                                                 */
/*  Author: Changsunche at 2010-09-19 16:18:35                                    */
/**********************************************************************************/


#include <iostream>
using namespace std;
int main(void)
{
 int a[200000],s=1,n=0,ans;
 while(cin>>a[s]){
 if (s>200000){break;}
    for( int i = 1; i < s; i++) {
        for( int j = i; j <= s; j++)
        {if( a[j] < a[i] ){n = a[j];a[j] = a[i];a[i] = n;}}} //泡沫排序
if(s%2!=0){ans=a[s/2+1];}
else if(s%2==0){ans=(a[s/2]+a[s/2+1])/2;}
s++;cout<<ans<<endl;}return 0;}

#4262: Re:TLE (1s) == 泡沫排序


soultama (NG)

學校 : 元朗商會中學
編號 : 7575
來源 : [81.152.13.199]
最後登入時間 :
2019-01-17 04:26:57

在這裡小弟用的是泡沫排序,把數字放進陣列後,用泡沫排序將他排順序,

再取中位數......

不過方法依然是TLE.....

-------------------------------------------------------------------

請問各位方法是什麼呢!?

/**********************************************************************************/
/*  Problem: d713 "中位数" from ACM 10107 c010:What is the Median? 加强版   */
/*  Language: CPP                                                                 */
/*  Result: TLE (1)  on ZeroJudge                                                 */
/*  Author: Changsunche at 2010-09-19 16:18:35                                    */
/**********************************************************************************/


#include
using namespace std;
int main(void)
{
 int a[200000],s=1,n=0,ans;
 while(cin>>a[s]){
 if (s>200000){break;}
    for( int i = 1; i < s; i++) {
        for( int j = i; j <= s; j++)
        {if( a[j] < a[i] ){n = a[j];a[j] = a[i];a[i] = n;}}} //泡沫排序
if(s%2!=0){ans=a[s/2+1];}
else if(s%2==0){ans=(a[s/2]+a[s/2+1])/2;}
s++;cout<<


泡抹排序是O(N^2)的排序方法, 會超時很合理...

#8317: Re:TLE (1s) == 泡沫排序


a450 (要学会宽容)

學校 : 福建省福州第十九中学
編號 : 33926
來源 : [118.189.34.85]
最後登入時間 :
2016-04-05 21:29:33

在這裡小弟用的是泡沫排序,把數字放進陣列後,用泡沫排序將他排順序,

再取中位數......

不過方法依然是TLE.....

-------------------------------------------------------------------

請問各位方法是什麼呢!?

/**********************************************************************************/
/*  Problem: d713 "中位数" from ACM 10107 c010:What is the Median? 加强版   */
/*  Language: CPP                                                                 */
/*  Result: TLE (1)  on ZeroJudge                                                 */
/*  Author: Changsunche at 2010-09-19 16:18:35                                    */
/**********************************************************************************/


#include
using namespace std;
int main(void)
{
 int a[200000],s=1,n=0,ans;
 while(cin>>a[s]){
 if (s>200000){break;}
    for( int i = 1; i < s; i++) {
        for( int j = i; j <= s; j++)
        {if( a[j] < a[i] ){n = a[j];a[j] = a[i];a[i] = n;}}} //泡沫排序
if(s%2!=0){ans=a[s/2+1];}
else if(s%2==0){ans=(a[s/2]+a[s/2+1])/2;}
s++;cout<<


泡抹排序是O(N^2)的排序方法, 會超時很合理...


我用的是插排 可是RE了
#8318: Re:TLE (1s) == 泡沫排序


rosynirvana (rosynirvana)

學校 : 不指定學校
編號 : 33880
來源 : [182.114.3.244]
最後登入時間 :
2017-07-24 00:02:04

在這裡小弟用的是泡沫排序,把數字放進陣列後,用泡沫排序將他排順序,

再取中位數......

不過方法依然是TLE.....

-------------------------------------------------------------------

請問各位方法是什麼呢!?

/**********************************************************************************/
/*  Problem: d713 "中位数" from ACM 10107 c010:What is the Median? 加强版   */
/*  Language: CPP                                                                 */
/*  Result: TLE (1)  on ZeroJudge                                                 */
/*  Author: Changsunche at 2010-09-19 16:18:35                                    */
/**********************************************************************************/


#include
using namespace std;
int main(void)
{
 int a[200000],s=1,n=0,ans;
 while(cin>>a[s]){
 if (s>200000){break;}
    for( int i = 1; i < s; i++) {
        for( int j = i; j <= s; j++)
        {if( a[j] < a[i] ){n = a[j];a[j] = a[i];a[i] = n;}}} //泡沫排序
if(s%2!=0){ans=a[s/2+1];}
else if(s%2==0){ans=(a[s/2]+a[s/2+1])/2;}
s++;cout<<


泡抹排序是O(N^2)的排序方法, 會超時很合理...


我用的是插排 可是RE了

insertion sort一样是O(n^2)