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

WA与AC的区别就在枚举的是分母还是分子。 不懂为什么会这样。。。。

Posted by sixshine at 2007-08-03 06:35:21 on Problem 1650
相当不爽

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:
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