HIToj--1076--Ordered Fractions(水题)
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(水题)的更多相关文章
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- 洛谷——P1458 顺序的分数 Ordered Fractions
P1458 顺序的分数 Ordered Fractions 题目描述 输入一个自然数N,对于一个最简分数a/b(分子和分母互质的分数),满足1<=b<=N,0<=a/b<=1, ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ...
- [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 ...
- gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,
1195: 相信我这是水题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 821 Solved: 219 Description GDUT中有个风云人 ...
- BZOJ 1303 CQOI2009 中位数图 水题
1303: [CQOI2009]中位数图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2340 Solved: 1464[Submit][Statu ...
- 第十一届“蓝狐网络杯”湖南省大学生计算机程序设计竞赛 B - 大还是小? 字符串水题
B - 大还是小? Time Limit:5000MS Memory Limit:65535KB 64bit IO Format: Description 输入两个实数,判断第一个数大 ...
随机推荐
- [USACO4.1]篱笆回路Fence Loops
题目:USACO Training 4.1(在官网上提交需加文件输入输出).洛谷P2738. 题目大意:给你一张图里的边集,让你求出这张图的最小环. 解题思路:求最小环很简单,用Floyd即可.最重要 ...
- 安装 glusterfs yum源报错
yum install glusterfs-server yum 一直报错 把/etc/yum.repos.d 备份 删除了所有文件,从测试机192..168.59.128上同步过来 一直报错 已加载 ...
- HDU 4366 Successor
Successor Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- ZOJ 2601 Warehouse Keeper
Warehouse Keeper Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Origin ...
- Android 4.4 KitKat NotificationManagerService使用具体解释与原理分析(二)__原理分析
前置文章: <Android 4.4 KitKat NotificationManagerService使用具体解释与原理分析(一)__使用具体解释> 转载请务必注明出处:http://b ...
- Bootstrap组件之输入框组
.input-group--设置div为输入框组: .input-group-lg..input-group-sm..input-group-xs--改变输入框组的尺寸: .input-group-a ...
- PHP第九课 正則表達式在PHP中的使用
今天内容 1.正則表達式 2.数学函数 3.日期函数 4.错误处理 正則表達式: 1.模式修正符 2.五个经常使用函数 另外一个正則表達式的站点:http://www.jb51.net/tools/z ...
- angularjs $location 服务
<!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...
- 使用isolation forest进行dns网络流量异常检测
代码如下,测试发现,是否对输入数据进行归一化/标准化对于结果没有影响: import numpy as np from sklearn.ensemble import IsolationForest ...
- hdoj--2516--取石子游戏(博弈)
取石子游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...