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:规律

Posted by Silgon at 2009-02-08 13:13:36 on Problem 2680
In Reply To:Re:规律 Posted by:Silgon at 2009-02-08 00:01:04
> 
> 可以这样吗?  
> 用f[n][0]表示n中00的对数,用f[n][1]表示n中1的个数   
> 当n=0时,f[n][0] = 0, f[n][1] = 1;
> 当n=1时, f[n][0] = 0, f[n][1] = 1;
> 当n>=2时,f[n][0] = f[n-2][0]+f[n-2][1];
>          f[n][1] = 2 * f[n][1];
> 则f[n][0]为所求解。
AC了!!!
#include <stdio.h>

int result[1001][401], n;

void compute(int a[], int c[], int n)
{
     int i, temp;
     memset(c, 0, sizeof(result[0]));
     if (n % 2 == 0)    c[1]++;
     else    c[1]--;
     for (i=1; i<=400; i++) {
         temp = a[i] + a[i] + c[i];
         if(temp < 0) {
                 temp += 10;
                 c[i] = temp % 10;
                 c[i+1]--;
                 continue;
         }
         c[i] = temp % 10;
         c[i+1] = temp / 10; 
     }
}

int main()
{
    int i, j;
    memset(result, 0, sizeof(result));
	for(i = 2; i<=1000; i++)         compute(result[i-1], result[i], i);
    while (scanf("%d", &n) != EOF) {
          if(n == 0) {
               printf("0\n");
               continue;
          }
          if(n == 1) {
               printf("0\n");
               continue;
          }
		  for(i=400; i>0; i--) 
                     if(result[n][i] != 0)   {
                             j = i;
                             break;
                     }
          for (; j > 0; j--)
				printf("%d", result[n][j]);
          printf("\n");
    }
    //system("pause");      
    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