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

O(9)的贪心还要32ms,这是为什么?

Posted by scuwf at 2011-12-09 14:56:18 on Problem 1775
#include<stdio.h>
int fac[10]={1,1,2,6,24,120,720,5040,40320,362880};
int main()
{
	int n,i,sign;
	while(scanf("%d",&n),n>=0)
	{
		sign=0;
		for(i=9;i>=0;i--)
		{
			if(n>=fac[i])
			{
				n-=fac[i];
				sign=1;
			}
		}
		if(sign && !n) printf("YES\n");
		else printf("NO\n");
	}
        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