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:为什么总是WA啊,哪里错了?

Posted by Sailing7 at 2008-05-05 13:38:31 on Problem 1338 and last updated at 2008-05-05 13:39:52
In Reply To:为什么总是WA啊,哪里错了? Posted by:BugKiller at 2008-03-17 22:12:42
算法错误。
例如temp=14时,if条件语句(temp%2==0||temp%3==0||temp%5==0)为真,
但实际上14不是ugly number。

> #include <stdio.h>
> int main(){
> 	int ugly[1700]={0};
> 	int n,index=1,temp;
> 	ugly[1]=1;
> 	for(scanf("%d",&n);n>0;scanf("%d",&n)){
> 		temp=ugly[index]+1;
> 		while(index<n){
> 			if(temp%2==0||temp%3==0||temp%5==0){
> 				index++;
> 				ugly[index]=temp;
> 			}
> 			temp++;
> 		}
> 		printf("%d\n",ugly[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