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

题意虽然没读懂,这题虽然不太会但是AC是没问题的!

Posted by nan5515522 at 2014-05-08 07:29:22 on Problem 1007
看讨论才知道原来就可以出现那么几个字母,当26个字母都可以出现呢!
顺便晒一下32ms水过的代码

#include<iostream>
#include<Cstdio>
using namespace std;
int hash[26];


struct Node
{
	char string[201];
	int result;
};

Node a[1000];
bool cmp(Node a1, Node a2)
{
	if(a1.result > a2.result)
		return true;
	return false;
}

void ShellSort(Node array[],int length)
{
	
	int d = length/2;   //设置希尔排序的增量
	int i ;
	int j;
	Node temp;
	while(d>=1)    
    {
		for(i=d;i<length;i++)    
		{    
			temp=array[i];
			j=i-d;
			while(j>=0 && array[j].result>temp.result)    
			{    
				array[j+d]=array[j];    
				j=j-d;    
			}    
			array[j+d] = temp;    
		}
		
		d= d/2;    //缩小增量    
	}
}

int main()
{
	int length, size, i, count = 0, j, k;

	char temp;
	scanf("%d%d", &length, &size);
	
	for(i = 0; i < size; i++)
	{
		for(j = 0; j < 26; j++)
		{
			hash[j] = 0;
		}
		
		a[i].result = 0;
		cin >> a[i].string;
		
		for(j = 0; j < length; j++)
		{
		    hash[a[i].string[j] - 'A'] ++;
			
		  
		    for(k = (a[i].string[j] - 'A') + 1; k < 26; k++)
		    {
		        a[i].result = a[i].result + hash[k];
		    }
		}
		
		//cout << a[i].result << endl;
	}
	
	ShellSort(a, size);

	for(i = 0; i < size; i++)
	{
		cout << a[i].string << 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