USACO Section 2.4: Fractions to Decimals
乍看题目感觉有难度,实际分析后其实是道简单题
/* ID: yingzho1 LANG: C++ TASK: fracdec */ #include <iostream> #include <fstream> #include <string> #include <map> #include <vector> #include <set> #include <algorithm> #include <stdio.h> #include <queue> #include <cstring> #include <cmath> #include <list> using namespace std; #define inf 10000000 ifstream fin("fracdec.in"); ofstream fout("fracdec.out"); int N, D; vector<int> rec; set<int> recset; int GCD(int a, int b) { ) return a; return GCD(b,a%b); } string intToString(int n) { string ret; ) "; while (n) { ); ret += tmp; n /= ; } reverse(ret.begin(), ret.end()); return ret; } int main() { fin >> N >> D; int gcd = GCD(N, D); N /= gcd, D/= gcd; ) { fout << N << ".0" << endl; ; } int first = N / D; int second = N % D; string res; ; ) { )) { for (; againindex < rec.size(); againindex++) { // cout << rec[againindex] << endl; ) { againindex++; break; } } break; } res = res + /D); rec.push_back(second*); recset.insert(second*); // cout << "second: " << second << endl; second = second * % D; } //cout << res << endl; //cout << againindex << endl; if (againindex) { res.insert(againindex-, "("); //cout << res << endl; res += ")"; } string ret = intToString(first) + "." + res; //cout << ret; ; i < ret.size(); i++) { fout << ret[i]; == && i > ) fout << endl; } != ) fout << endl; //if (first > 0) fout << first << "." << res << endl; //else fout << "0." << res << endl; ; }
USACO Section 2.4: Fractions to Decimals的更多相关文章
- 【USACO 2.4】Fractions to Decimals(分数转小数)
题意:给你N/D的分数,让你输出等价的小数,如果是循环小数,用括号把循环节包起来.如果是整数,后面保留一位小数.每行最多输出76个字符. 题解:模拟除法,如果余数是第二次出现,则代表第一次出现的位置到 ...
- 洛谷P1530 分数化小数 Fractions to Decimals
P1530 分数化小数 Fractions to Decimals 103通过 348提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交 讨论 题解 最新讨论 暂时没有讨论 题目 ...
- Luogu P1530 分数化小数 Fractions to Decimals(模拟)
P1530 分数化小数 Fractions to Decimals 题意 题目描述 写一个程序,输入一个形如\(N/D\)的分数(\(N\)是分子,\(D\)是分母),输出它的小数形式.如果小数有循环 ...
- YTU 1439: 2.4.5 Fractions to Decimals 分数化小数
1439: 2.4.5 Fractions to Decimals 分数化小数 时间限制: 1 Sec 内存限制: 64 MB 提交: 194 解决: 13 题目描述 写一个程序,输入一个形如N/ ...
- USACO Section 2.1 Ordered Fractions
/* ID: lucien23 PROG: frac1 LANG: C++ */ #include <iostream> #include <fstream> #include ...
- USACO Section 2.1 Ordered Fractions 解题报告
题目 题目描述 给定一个数N(1<=N<=160),需要产生所有的分数,这些分数的值必须要在0~1之间.而且每个分数的分母不能超过N.如下例所示: N = 5 产生所有的分数:0/1 1/ ...
- USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)
usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...
- USACO Section 3.3: Riding the Fences
典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...
- USACO Section 3.3 Camlot(BFS)
BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...
随机推荐
- 十个优秀的C语言学习资源推荐
学习C语言,需要一点一滴,沉下心来,找个安静的地方,泡上一杯咖啡,在浓郁的香味中一起品味她.-- Boatman Yang 人们通常认为计算机编程很烦,但是有些人却从中发现了乐趣.每一个程序员不得不跟 ...
- 22、DDMS(转载)
本文是转载,出处为http://www.xuebuyuan.com/1291595.html 如需删除本文,请私信我,谢谢 DDMS DDMS是一款Google* 提供的应用,可作为独立的工具运行,也 ...
- BackgroundWorker
Constants.Worker = new BackgroundWorker(); Constants.Worker.WorkerSupportsCancellation = true; Const ...
- C#中实现VB中的CreateObject方法
经常看到有些VB的例子中直接用个CreateObject就可调用系统功能(大多是COM对象),像用户设定,网络设定等等.虽然C#中可以通过使用VB的命名空间的方法来调用CreateObject函数,但 ...
- PE文件信息获取工具-PEINFO
能实现基本的信息获取 区段信息 数据目录信息 导入表函数分析 导出表函数分析,能同时解析只序号导出和以函数名序号同时导出的函数 FLC计算 需要源码的可以留邮箱.
- js实用功能
//日期格式转换 Date.prototype.format = function (format) { /* * eg:format="yyyy-MM-dd hh:mm: ...
- 在 Java EE 组件中使用 Camel Routes
摘要:你可以通过集成 Camel 和 WildFly 应用服务器(使用 WildFly-Camel 子系统)在 Java EE 组件中开始使用 Apache Camel Routes. [编者按]作者 ...
- 总结 | 如何测试你自己的 RubyGem
如何测试一个Gem gem 开发完了,想要给别人用,那就需要测试啊,测试一个 gem 其实很简单,这里我们用 minitest 为例, rspec 也一样适用.先来看看我们当前这个 gem 的目录结构 ...
- 【译】使用 Python 编写虚拟机解释器
[译]如何使用 Python 创建一个虚拟机解释器? 原文地址:Making a simple VM interpreter in Python 更新:根据大家的评论我对代码做了轻微的改动.感谢 ro ...
- 【四】php字符串操作
1.trim函数,我们队trim函数并不陌生,用于去除字符串两头的空白符.php的trim方法也可以做到这一点,但是还可以使用第二个参数,用于规定你在两头去掉什么.php中还有 ltrim 和 rtr ...