Usaco Ordered Fractions

Source: Internet
Author: User

The test instructions is given an n, and the output is sorted by a nonnegative fraction of all the denominator less than N.

/*id:modengd1prog:frac1lang:c++*/#include <iostream> #include <stdio.h> #include <memory.h># Include <queue>using namespace Std;bool vis[261][261];//, the score after the quote may exist after numerator equal score int gcd (int x,int y) {return y= =0?X:GCD (y,x%y);}    struct fra{//numerator and denominator int num1,num2;        FRA (int a,int b)//constructs numerator {int C=GCD (A, b) at the same time;        NUM1=A/C;    NUM2=B/C; } bool Friend operator < (FRA f1,fra f2) {return f1.num1*f2.num2>f2.num1*f1.num2;//-pass compare size to sort by priority queue so yes    Greater than number}};int main () {freopen ("frac1.in", "R", stdin);    Freopen ("Frac1.out", "w", stdout);    int N;    Priority_queue<fra> Q;    memset (vis,false,sizeof (VIS));    scanf ("%d", &n);    if (n==0)//press into 0 Q.push (FRA (0,0));    Else Q.push (FRA (0,1));            for (int j=1;j<=n;j++)//enumeration denominator {for (int i=1;i<j;i++)//enumeration molecule {fra F=fra (i,j);            if (vis[f.num1][f.num2])//If the enumerated numerator is already equal to the previous one, the continue is ignored; Vis[f.num1][f.num2]=true;        Q.push (f);    }} if (n!=0)//press into 1 Q.push (FRA); while (!        Q.empty ())//Output {fra now=q.top ();        Q.pop ();    cout<<now.num1<< '/' <<now.num2<<endl; } return 0;}

  

Usaco Ordered Fractions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.