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

怎么还是WA呢?想不通啊

Posted by Essence_me at 2005-09-10 11:30:55 on Problem 2346
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <memory.h>
int num[100000],max;
void work(int i)
{
	int sum=0;
	while(i>0)
	{
		sum+=i%10;
		i/=10;
	}
	num[sum]++;
    if(sum>max)max=sum;
}

int main()
{
	int k1,k2,n,i;
	long sum;
	scanf("%d",&n);
	max=0;
	memset(num,0,sizeof(int)*((int)exp(n/2*log(10))-1));
	for(i=0;i<exp((n/2)*log(10))-1;i++)
	{
		work(i);
	}
	sum=0;	
	for(i=0;i<=max;i++)
	{
		sum+=num[i]*num[i];
	}
	printf("%ld\n",sum);
	system("PAUSE");
}

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