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

Re:优化逆序数计算后认为本题瓶颈不在逆序数上,另外请0MS的提供一下经验

Posted by lovestream at 2011-04-08 21:42:47 on Problem 1007
In Reply To:优化逆序数计算后认为本题瓶颈不在逆序数上,另外请0MS的提供一下经验 Posted by:hsmwzj at 2010-08-04 16:09:32
> 按照讨论上对逆序数计算做了优化后,执行时间仍然不变,用了16MS,故此题耗时主要在排序上,估计用时0MS的不是用O(n*n)的排序方法,而是O(nlgn)的。哪位耗时0MS的可以来贡献一下?

贴下我代码,有点水。
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int n,m,flag[101],ans[101];
string s[101];

bool cmp(int x,int y)
{
	return (flag[x] < flag[y]);
}

int main()
{
	int i,j,k;
	cin>>n>>m;
	memset(flag,0,sizeof(flag));
	for(i=0; i<m; i++)
		ans[i] = i;
	for(i=0; i<m; i++)
	{
		cin>>s[i];
		for(j=0; j<n; j++)
		{
			for(k=j+1; k<n; k++)
			{
				if(s[i][k] < s[i][j])
					flag[i]++;
			}
		}
	}
	stable_sort(ans,ans+m,cmp);
	for(i=0; i<m; i++)
		cout<<s[ans[i]]<<endl;
	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