zoukankan      html  css  js  c++  java
  • USACOOrdered Fractions

    http://ace.delos.com/usacoprob2?a=B9V6yMSRsQa&S=frac1

    对这一题彻底无语。。。。。

    简单的排序,竟然放在chapter2中。。。。

    而最可恨的是USACO的评测。。。

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
     
    const double XX=0.000000001;
    struct node{
        double d;
        int x,y;
        friend bool operator < (node a,node b)
        {
            return a.d<b.d;
        }
    }a[10000];
    
    bool check(int x,int y)
    {
        for (int i=2;i<=x;i++)
            if (x%i==0 && y%i==0)
                return false;
        return true;
    }
    
    int main()
    {
        freopen("frac1.in","r",stdin);
        freopen("frac1.out","w",stdout);
        int n,sum=0;
        cin>>n;
        a[++sum].d=0; a[sum].x=0; a[sum].y=1;         //看到这里,如果我不加这一句,而直接从i=0开始循环,自己的机子上答案正确,USACO上提交,输出的第一行是0/2,真是无语了。。。
        for (int i=1;i<=n;i++)
            for (int j=i;j<=n;j++)
            if (check(i,j))
            {
                a[++sum].d=double(i)/double(j);
                a[sum].x=i; a[sum].y=j;
            }
        sort(a+1,a+sum+1);
        a[0].d=-1;
        for (int i=1;i<=sum;i++)
        if (a[i].d-a[i-1].d>XX)
            cout<<a[i].x<<'/'<<a[i].y<<endl;
        return 0;
    }
  • 相关阅读:
    hdu 4460spfa用map来实现
    hdu 2579
    hdu 2845
    hdu 4462
    hdu 4557
    hdu 4639
    URAL 2078 Bowling game
    UVA
    HDU 5773 The All-purpose Zero 脑洞LIS
    Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学
  • 原文地址:https://www.cnblogs.com/ay27/p/2728103.html
Copyright © 2011-2022 走看看