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

测试数据运行了都对,但不能够AC,请你们帮我看一下,错在哪里了,谢谢。

Posted by ccnuteam2 at 2008-09-21 11:35:13 on Problem 1338
In Reply To:请问怎样不超时 Posted by:SinsongLew at 2007-04-15 14:26:25
#include <stdio.h>
int min(int ,int);
int main()
{
	int n, i,k, j,cur;
	while(1){
		scanf("%d",&n);
		if(n==0)  break;
		i=2;    j=3;	k=5;
		n--;    cur=1;
		while(n--){   //由于第一个数已知,所以要求第n个数,只需要循环n-1次,每次循环,得到一个符合条件的数,这个数是从小到大递增的。
                while(i<=cur)  i+=2;   //i为2的倍数。
		while(j<=cur)  j+=3;   //j为3的倍数。
		while(k<=cur)  k+=5;   //k为5的倍数。
		cur=min(i,min(j,k));  //cur是当前的符合条件的数。
		}
       printf("%d\n",cur);
	   }
	return 0;
}
int min(int x,int y)
{
	if(x<y)  return x;
	else  return y;
}

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