USACO Section 2.1 Ordered Fractions
/*
ID: lucien23
PROG: frac1
LANG: C++
*/ #include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std; typedef struct Fraction
{
int numerator;
int denominator;
Fraction(){}
Fraction(int x, int y)
{
numerator = x;
denominator = y;
}
} Fraction; bool isPrimes(int x, int y); bool compFrac(Fraction frac1, Fraction frac2)
{
if (frac1.numerator/(double)frac1.denominator < frac2.numerator/(double)frac2.denominator)
{
return true;
}
return false;
} int main()
{
ifstream infile("frac1.in");
ofstream outfile("frac1.out");
if(!infile || !outfile)
{
cout << "file operation failure!" << endl;
return -1;
} int N;
infile >> N; vector<Fraction> fractions;
fractions.push_back(Fraction(0, 1));
fractions.push_back(Fraction(1, 1)); for (int i=1; i<=N; i++)
{
for (int j=1; j<i; j++)
{
if (isPrimes(j, i))
{
fractions.push_back(Fraction(j, i));
}
}
} sort(fractions.begin(), fractions.end(), compFrac); for (vector<Fraction>::iterator it=fractions.begin(); it!=fractions.end(); it++)
{
outfile << it->numerator << "/" <<it->denominator << endl;
} return 0;
} /*
*推断两数是否互质
*/
bool isPrimes(int x, int y)
{
for (int i=2; i<=x; i++)
{
if (x%i == 0 && y%i == 0)
{
return false;
}
} return true;
}
USACO Section 2.1 Ordered Fractions的更多相关文章
- USACO Section 2.1 Ordered Fractions 解题报告
题目 题目描述 给定一个数N(1<=N<=160),需要产生所有的分数,这些分数的值必须要在0~1之间.而且每个分数的分母不能超过N.如下例所示: N = 5 产生所有的分数:0/1 1/ ...
- 【USACO 2.1】Ordered Fractions
/* TASK: frac1 LANG: C++ URL: http://train.usaco.org/usacoprob2?S=frac1&a=dbgwn5v2WLr SOLVE: 直接枚 ...
- USACO 2.1 Ordered Fractions
Ordered Fractions Consider the set of all reduced fractions between 0 and 1 inclusive with denominat ...
- 洛谷P1458 顺序的分数 Ordered Fractions
P1458 顺序的分数 Ordered Fractions 151通过 203提交 题目提供者该用户不存在 标签USACO 难度普及- 提交 讨论 题解 最新讨论 暂时没有讨论 题目描述 输入一个 ...
- 洛谷——P1458 顺序的分数 Ordered Fractions
P1458 顺序的分数 Ordered Fractions 题目描述 输入一个自然数N,对于一个最简分数a/b(分子和分母互质的分数),满足1<=b<=N,0<=a/b<=1, ...
- 洛谷 P1458 顺序的分数 Ordered Fractions
P1458 顺序的分数 Ordered Fractions 题目描述 输入一个自然数N,对于一个最简分数a/b(分子和分母互质的分数),满足1<=b<=N,0<=a/b<=1, ...
- USACO Ordered Fractions
首先看一下题目 Consider the set of all reduced fractions between 0 and 1 inclusive with denominators less t ...
- USACO Section 2.4: Fractions to Decimals
乍看题目感觉有难度,实际分析后其实是道简单题 /* ID: yingzho1 LANG: C++ TASK: fracdec */ #include <iostream> #include ...
- USACO Section2.1 Ordered Fractions 解题报告
frac1解题报告 —— icedream61 博客园(转载请注明出处)---------------------------------------------------------------- ...
随机推荐
- 我的github教程
这篇文章记录个人常用的一些命令,和记不住的一些命令. 安装 在 Windows 上安装 Git ,有个叫做 msysGit 的项目提供了安装包: http://msysgit.github.io/ 完 ...
- iOS- Size Class使用教程
1:它引入了一种新的概念,抛弃传统意义上我们适配时所谓的具体宽高尺寸,把屏幕的宽和高分别分成两种情况:Compact-紧凑, Regular-正常(Any-任意,其实就是这2种的组合,所以我没分成3种 ...
- Laravel5.1学习笔记19 EloquentORM 入门
Eloquent:入门 简介 定义模型(model) Eloquent 模型规范 取出多个模型 取出单个模型 / 集合 取出集合 插入更新模型 基本插入 基本更新 大批量赋值 删除模型 软删除 查询 ...
- [转]Wote用python语言写的imgHash.py
#!/usr/bin/python import glob import os import sys from PIL import Image EXTS = 'jpg', 'jpeg', 'JPG' ...
- 【转】升级还是权谋?从USB PD 2.0到3.0
原文出处 http://www.eetop.cn/blog/html/43/n-433743.html 如同iPhone的出现,才让智能机真正主导手机市场一样,Type-C口发布后,USB PD才正式 ...
- #2028 Lowest Common Multiple Plus
http://acm.hdu.edu.cn/showproblem.php?pid=2028 应该是比较简单的一道题啊...求输入的数的最小公倍数. 先用百度来的(老师教的已经不知道跑哪去了)辗转相除 ...
- Resetting the SMC & PRAM
Resetting the SMC & PRAM on portables with a battery you should not remove on your own 1. Shut d ...
- 扩增子分析QIIME2-4分析实战Moving Pictures
本示例的的数据来自文章<Moving pictures of the human microbiome>,Genome Biology 2011,取样来自两个人身体四个部位五个时间点 ...
- maven常用dos命令
在平常的开发中可能会经常切换开发中的一些工具,有时就会对一些常用的命令给忘记了 这里特别记录下来方便以后使用: 1.查看maven版本:mvn -c 2.一件构建启动Tomcat:mvn tomcat ...
- LOJ——#6277. 数列分块入门 1
~~推荐播客~~ 「分块」数列分块入门1 – 9 by hzwer 浅谈基础根号算法——分块 博主蒟蒻,有缘人可直接观摩以上大佬的博客... #6277. 数列分块入门 1 题目大意: 给出一个长为 ...