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:感觉对的代码AC不了,感觉错的代码却AC了,真郁闷

Posted by yunyifly at 2007-05-30 21:05:37 on Problem 1003
In Reply To:感觉对的代码AC不了,感觉错的代码却AC了,真郁闷 Posted by:yunyifly at 2007-05-30 21:03:07
刚开始用float写,两个都AC不了,检查了半天,最后用double就过了。
如果照我说的加个ceil的话过不了,感觉这题的数据有问题。

> 这是AC的代码。
> #include<iostream>
> #include<cmath>
> using namespace std;
> 
> int main()
> {
> 	int card[600];
> 	double sum=0;
> 	int temp=0;
> 	int pretemp=0;
> 	int i=2;
> 	while(sum<5.21)
> 	{
> 		sum+=(1/double(i));
> 		pretemp=temp+1;
> 		temp=sum*100;
> 		for(int j=pretemp;j<=temp;j++)
> 		{
> 			card[j]=i-1;
> 		}
> 		i++;
> 	}
> 	cin>>sum;
> 	while(sum>0.001)
> 	{
> 
> 		cout<<card[int(sum*100)]<<" card(s)"<<endl;
> //感觉上面这句应该改成cout<<card[int(ceil(sum*100))]<<" card(s)"<<endl;
> 		cin>>sum;
> 	}
> 	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