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

141MS险过,谨记1!+2!+......n!<(n+1)!就行!虽然一次AC,但效率不高,贴上代码仅供参考,如有优化感激不尽

Posted by 201501060326 at 2016-02-22 18:05:31 on Problem 1775
#include <stdio.h>
int find(int n)
{
    if(n==0)
        return 1;
    else
        return n*find(n-1);
}
int solve(int n,int k)
{
    int i,flag=0;
    for(i=9; i>=0; i--)
    {
        if(n==find(i)&&i<k)
        {
            flag=1;
            break;
        }
        else if(n>find(i)&&i<k)
        {
            k=i;
            break;
        }
    }
    if(flag==0&&k>0)
        solve(n-find(k),k);
    else
        return flag;
}
int main()
{
    int n,i;
    while(scanf("%d",&n),n>=0)
    {
        if(solve(n,10)==1)
            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