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:用map吧,代码超短,速度还行。你这复杂度也太高点了。。。

Posted by MasterLuo at 2009-01-01 20:41:32 on Problem 2418 and last updated at 2009-01-01 20:42:53
In Reply To:讨论讨论吧!AC了的人给点提示好吗?? Posted by:xhu_li at 2009-01-01 20:30:35
> 这道题看了看其他资料,说要用二叉树来做,不用二叉树难道就不行吗??那位高手给点提示!!
> 以下是我写的代码,没有涉及二叉树,但是很遗憾,超时,在自己的机器上测了数据是对的,帮帮忙,看看可以哪里可以修改以下,提高下效率
> 
> #include<stdio.h>
> #include<string.h>
> #include<math.h>
> struct tree
> {
> 	char name[30];
> 	float per;
> };
> struct tree str[10000];
> int b[10000],t;
> int f(char *s)
> {
> 	int i;
> 	for(i=0;i<t;i++)
> 	{
> 		if(strcmp(str[i].name,s)==0)
> 			return i;
> 	}
> 	strcpy(str[t].name,s);
> 	t++;
> 	return t-1;
> }
> void main()
> {
> 	char s[30],str1[30];
> 	int i,n,j,count=0;
> 	float k;
> 	memset(b,0,sizeof(b));
> 	t=0;
> 	while(gets(s)!=NULL)
> 	{
> 		count++;
> 		n=f(s);
> 		b[n]++;
> 	}
> 	for(i=0;i<t;i++)
> 	{
> 		str[i].per=b[i]*1.0/count;
> 	}
> 	for(i=0;i<t-1;i++)
> 	{
> 		for(j=i;j<t;j++)
> 		{
> 			if(strcmp(str[i].name,str[j].name)>0)
> 			{
> 				strcpy(str1,str[i].name);
> 				strcpy(str[i].name,str[j].name);
> 				strcpy(str[j].name,str1);
> 				k=str[i].per;
> 				str[i].per=str[j].per;
> 				str[j].per=k;
> 			}
> 		}
> 	}
> 	for(i=0;i<t;i++)
> 		printf("%s %.4f\n",str[i].name,str[i].per*100);
> }

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