| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
WA与AC的区别就在枚举的是分母还是分子。 不懂为什么会这样。。。。相当不爽
Source
Problem Id:1650 User Id:sixshine
Memory:128K Time:0MS
Language:C++ Result:Wrong Answer
Source
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a,ans=1E10;
long i,L,k,D,N;
cin>>a>>L;
for(i=1;i<=L;i++)
{
if (ans<1E-14) ans=0;
k=i/a;
if (k==0)
k=1;
if (k>L)
k=L;
if (ans>abs(a-(double)i/k))
{
ans=abs(a-(double)i/k);
N=i;
D=k;
}
if (k<L)
k++;
if (ans>abs(a-(double)i/k))
{
ans=abs(a-(double)i/k);
N=i;
D=k;
}
}
cout<<N<<' '<<D<<endl;
}
**************************************************
WA与AC的区别就在枚举的是分母还是分子。 不懂为什么会这样。。。。
Source
Problem Id:1650 User Id:sixshine
Memory:228K Time:15MS
Language:G++ Result:Accepted
Source
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a,ans=1E10;
long i,L,k,D,N;
cin>>a>>L;
for(i=1;i<=L;i++)
{
if (ans<1E-14) ans=0;
k=a*i;
if (k==0)
k=1;
if (k>L)
k=L;
if (ans>abs(a-(double)k/i))
{
ans=abs(a-(double)k/i);
N=k;
D=i;
}
if (k<L)
k++;
if (ans>abs(a-(double)k/i))
{
ans=abs(a-(double)k/i);
N=k;
D=i;
}
}
cout<<N<<' '<<D<<endl;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator