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:不用动态规划也能a啊,^-^!

Posted by 14310320733 at 2015-07-15 08:59:18 on Problem 2081
In Reply To:为什么老是runtime error,快崩溃了,谁能告诉我why Posted by:csuyuanxing at 2010-04-30 02:38:39
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int b[5000000];
int a[5000000];
int n,i,j,k,m=0;
int main()
{
    while(~scanf("%d",&n))
    {
        if(n==-1)
            break;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        a[1]=1;
        b[1]=1;
        b[0]=1;
        if(a[n]!=0&&n!=0)
            printf("%d\n",a[n]);
        else
        {
            for(i=1; i<=n; i++)
            {
                m=a[i-1]-i;
                if(m>0)
                {
                    if(b[m]==0)
                    {
                        a[i]=m;
                        b[m]=1;
                    }
                    else
                    {
                        a[i]=a[i-1]+i;
                        b[a[i]]=1;
                    }
                }
                else
                {
                    a[i]=a[i-1]+i;
                    b[a[i]]=1;
                }
            }
            printf("%d\n",a[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