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

靠,这么简单的题目也会有问题!不要用模拟法。还是数学方法好。

Posted by huicpc15 at 2005-11-06 16:43:56 on Problem 2000
//模拟法,SAPLE 中的10000和1000不对,为什么?
#include <stdio.h>
#include<stdlib.h>
int main()
{
    int j=1,index;
    int a[100001];
    //a=(int *)malloc(101*sizeof(int));
    for(index=1;index<100001;index+=(j-1))
    {
        int J;
        for(J=0;J<j;J++)
          a[index+J]=j;
        j++;    
    }

    for(index=2;index<10001;index++)
    a[index]+=a[index-1];
	while(1)
	{
		scanf("%d",&index);
		if(!index) break;
		printf("%d\n",a[index]);
	}
    return 0;
}
//数学方法,AC了
#include <stdio.h>
int fun(int x)
{
    int n;
    for(n=1;;n++)
    if(2*x<=(n*(n+1)))
    {
        int r;
        n--;
        r=n*(n+1)*(2*n+1)/6+(x-n*(n+1)/2)*(n+1); 
        return r;
    }
}
int main()
{
  int x,res;
  while(1)
  {
    scanf("%d",&x);
    if(!x) break;
    res=fun(x);
    printf("%d %d\n",x,res);        
  }    
}

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