Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

表示就不理解了 明明和别人的想法是一样的。。。为啥我tle= =求大牛指导

Posted by GSMU at 2012-06-04 20:09:36 on Problem 1007
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include <algorithm>

using namespace std;
char in[51][101];
int m,n,temp;
int cal(char a[])
{
    int result=0;
    int len=n;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
              result++;
        }
    }
    return result;
}
int cmp(const void *e1,const void *e2)
{
    int *p1,*p2;
    p1=(int *)e1;
    p2=(int *)e2;
    return *p1-*p2;
}
int main()
{
    int result[51],order[51];
    while(cin>>n>>m)
    {
        for(int i=0;i<m;i++)
        {
            result[i]=0;
        }
        for(int i=0;i<m;i++)
        {
            cin>>in[i];
            order[i]=result[i]=cal(in[i]);
        }
        qsort(order,m,sizeof(int),cmp);

        for(int i=0;i<m;i++)
         {
             for(int j=0;j<m;j++)
	            if(result[j]==order[i])
	           {
		         cout<<in[j]<<endl;
                 result[j]=-1;

	            }
      }

    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator