Ordered Fractions

  Source : Unknown
  Time limit : 3 sec   Memory limit : 32 M

Submitted : 1510, Accepted : 496

Consider the set of all reduced fractions between 0 and 1 inclusivewith denominators less than or equal to N.

Here is the set when N = 5:

0/1 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 1/1

Write a program that, given an integer N between 1 and 160 inclusive,prints the fractions in order of increasing magnitude.

INPUT FORMAT

Several lines with a single integer N in each line.Process to the end of file.

SAMPLE INPUT

5
5

OUTPUT FORMAT

One fraction per line, sorted in order of magnitude.print a blank line after each testcase.

SAMPLE OUTPUT

0/1
1/5
1/4
1/3
2/5
1/2
3/5
2/3
3/4
4/5
1/1 0/1
1/5
1/4
1/3
2/5
1/2
3/5
2/3
3/4
4/5
1/1
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
int a,b;
double s;
}num[100010];
int cmp(node s1,node s2)
{
return s1.s<s2.s;
}
int gcd(int a,int b)
{ return b==0?a:gcd(b,a%b);
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int cnt=0;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=i;j++)
{
if(gcd(i,j)==1)
{
num[cnt].a=j;
num[cnt].b=i;
num[cnt].s=j*1.0/i;
cnt++;
}
} }
sort(num,num+cnt,cmp);
for(int i=0;i<cnt;i++)
printf("%d/%d\n",num[i].a,num[i].b);
printf("\n");
}
return 0;
}

HIToj--1076--Ordered Fractions(水题)的更多相关文章

  1. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  2. 洛谷——P1458 顺序的分数 Ordered Fractions

    P1458 顺序的分数 Ordered Fractions 题目描述 输入一个自然数N,对于一个最简分数a/b(分子和分母互质的分数),满足1<=b<=N,0<=a/b<=1, ...

  3. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  4. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  5. ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)

    1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 112[ ...

  6. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

  7. gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,

    1195: 相信我这是水题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 821  Solved: 219 Description GDUT中有个风云人 ...

  8. BZOJ 1303 CQOI2009 中位数图 水题

    1303: [CQOI2009]中位数图 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2340  Solved: 1464[Submit][Statu ...

  9. 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题

    B - 大还是小? Time Limit:5000MS     Memory Limit:65535KB     64bit IO Format: Description 输入两个实数,判断第一个数大 ...

随机推荐

  1. javascript 继承之拷贝,原型,类式

    // 拷贝继承,在子类内调用父类并修正this指向,再通过for in 拷贝父类的方法实现继承,具体实现如下代码 : function Tab(){//父类构造函数 this.name='aaa'; ...

  2. 使用Jmeter工具对http接口进行压力测试

    1.访问apache官网下载Jmeter工具 地址:https://jmeter.apache.org/download_jmeter.cgi 2.解压压缩包后运行bin目录下jmeter.bat启动 ...

  3. Docker安装MySQL忽略大小写问题的问题

    原文:Docker安装MySQL忽略大小写问题的问题 连接MySQL: 查看当前mysql的大小写敏感配置show global variables like '%lower_case%';+---- ...

  4. 【codeforces 589G】Hiring

    [题目链接]:http://codeforces.com/problemset/problem/589/G [题意] 有n个人; 每个人每天在开始工作之前,都需要di单位的准备时间,然后才能开始工作; ...

  5. HDU 4366 Successor

    Successor Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID:  ...

  6. 完毕乔布斯的梦想:一个免费wifi共享的乌托邦

    早在2007年推出iPhone时,乔布斯就提出这种如果:商业区与居民区的wifi路由器全民开放,实现与路人共享网络之便.能够想象,那算是一个wifi共享的乌托邦. 数年过去了,乔布斯的梦想依然没能全然 ...

  7. [MST] Restore the Model Tree State using Hot Module Reloading when Model Definitions Change

    n this lesson, we will set up Hot Module Reloading(HMR), making it possible to load new definitions ...

  8. 关于functioncharts饼状图篇

    关于functioncharts饼状图(仅限饼状图) TODO: 1.饼状图没有数据情况下,显示:no data to display 2,解决的方法:自己定义处理.显示图像或其他内容

  9. linux+apache+mysql+php平台构建及环境配置

    1.我使用的centos6.安装时已经选择安装apach.mysql,事实上在运行下列两行命令的时候又对其进行了更新.所以说装的时候能够不安装,免得浪费时间. yum install php-mysq ...

  10. ,典型递归问题-F(1025)mod 5 的值

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...