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


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


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

再取中位數......

不過方法依然是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)


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

再取中位數......

不過方法依然是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 (要学会宽容)


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

再取中位數......

不過方法依然是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)


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

再取中位數......

不過方法依然是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)