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

请HAWK来看看这是为什么

Posted by breaddawson at 2004-10-19 00:45:10 on Problem 1922
我写了程序但是WRONG ANSWER
找了半天错误都没有找到
直到我请教了别人,看了他们的代码
然后改掉了一个地方

我把本题的速度加了判断条件

(var<40)&&(var>0)

这是因为题目中写着:

Vi is a positive integer less than 40

可是这样是WRONG ANSWER
而我把<40改成<=40就对了
而且任何判断条件都不加也是对的

不明白为什么会这样
请HAWK给个解释
谢谢~~

附:更改前后的代码

更改前:WRONG ANSWER:

#include "stdio.h"
#include "math.h"

void main()
{
	int number,i,var,start,sign;
	double time,min;
	scanf ("%d",&number);
	while (number)
	{
		sign=1;
		for (i=0;i<number;i++)
		{
			scanf("%d%d",&var,&start);
			if ((start>=0)&&(var<40)&&(var>0))
			{
				time=16200/(double)var+start;
			//	printf("%f",time);
				if (sign)
				{
					min=time;
					sign=0;
			//		printf("%f",min);
				}
			}
			min=time<min?time:min;
		}
		printf("%d\n",(int)ceil(min));
		scanf ("%d",&number);
	}
}
更改后:ACCEPTED

#include "stdio.h"
#include "math.h"

void main()
{
	int number,i,var,start,sign;
	double time,min;
	scanf ("%d",&number);
	while (number)
	{
		sign=1;
		for (i=0;i<number;i++)
		{
			scanf("%d%d",&var,&start);
			if ((start>=0)&&(var<=40)&&(var>=0))
			{
				time=16200/(double)var+start;
			//	printf("%f",time);
				if (sign)
				{
					min=time;
					sign=0;
			//		printf("%f",min);
				}
			}
			min=time<min?time:min;
		}
		printf("%d\n",(int)ceil(min));
		scanf ("%d",&number);
	}
}




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