[题目] Section 2.1 OrderedFractions(USACO)
来源:互联网 发布:淘宝客怎么开通教程 编辑:程序博客网 时间:2024/06/05 22:40
[题意]给出一个整数N,找出一组真分数,使得他们的分子分母都不大于N.以分数形式从小到大输出这组数。
[思路]不要想如何排序了,set解决!枚举所有分数,先判断是否最简,然后加入set中即可。
[代码]
#include<cstdio>#include<iostream>#include<set>#include<string>#include<cstdlib>using namespace std;struct haha{ double num; string str; bool operator < (consthaha &a) const { return a.num>num; }}ha;int main(){ int n;cin>>n; set<haha> se; set<haha>::iterator it; for(int i=2;i<=n;i++) for(int j=1;j<i;j++){ if((i%j)>0||j==1){ char st[10]; char st2[10]; sprintf(st,"%d", j); sprintf(st2,"%d", i); ha.num=(double)j/(double)i; strings=st;s=s+'/';s+=st2; ha.str=s; se.insert(ha); } } cout<<"0/1"<<endl; for(it=se.begin();it!=se.end();it++) cout<<it->str<<endl; cout<<"1/1"<<endl;}
0 0
- [题目] Section 2.1 OrderedFractions(USACO)
- [题目] Section 2.1 The Castle(USACO)
- USACO Section 2.1 题解
- USACO Section 2.1
- USACO Section 2.1
- [USACO Training] Section 2.1
- [题目] Section 1.2 Milking Cows(USACO)
- Usaco Section 2.1 The Castle
- Usaco Section 2.1 Ordered Fractions
- USACO Section 2.1 The Castle
- USACO Section 2.1 Ordered Fractions
- USACO Section 2.1 Healthy Holsteins
- USACO Section 2.1 Hamming Codes
- USACO Section 2.1 The Castle
- USACO Section 2.1 Healthy Holsteins
- USACO Section 2.1 Hamming Codes
- USACO Section 2.2 Preface Numbering - 题目只是自始自终没太懂..
- USACO Section 5.1 Musical Themes - 题目转换以及KMP..
- 并发编程--使用锁实现同步
- Matlab产品家族工具箱介绍!
- CSS中的table
- POJ 3352 & 3177 无向图的边-双连通分量(无重边 & 重边)
- 内容观察者
- [题目] Section 2.1 OrderedFractions(USACO)
- Linux中的platform
- hdu-1715 (大数加法模板)
- JS中定时器的用法以及窗口的滚动条函数
- Swift中的UIKit重力学(一)
- [题目] Section2.1 HealthyHolsteins
- Truetime2.0 Beta7安装过程
- 常用排序算法之javascript实现
- SQLite在多线程并发访问的应用