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格(网上都这么说,似乎是个 ...
随机推荐
- js判断浏览器滚动条是否拉到底
$(window).scroll(function(){ // 当滚动到最底部以上n像素时, 加载新内容 if ($(document).height() - $(this).scrollTop() ...
- 关于通过JS识别浏览器类型的方法
JS检测浏览器类型的方法 网络上一般采用navigator.userAgent判断浏览器标识的办法,但是有个麻烦的问题是IE11不断升级之后,IE11的userAgent变成: "Moz ...
- 【bzoj1002】[FJOI2007]轮状病毒
1002: [FJOI2007]轮状病毒 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4381 Solved: 2393[Submit][Statu ...
- phonegap上传以及下载图片
在phonegap中,有时我们需要从服务器下载图片以及上传图片,这个时候可以用到官方提供的一个插件:FileTransfer 首先通过命令添加插件: cordova plugin add org.ap ...
- 3-Highcharts曲线图之显示点值折线图
直接上代码 根据代码注释讲解 <!DOCTYPE> <html lang='en'> <head> <title>3-Highcharts曲线图之显示 ...
- wifi current SSID
1. 引入头,#import <SystemConfiguration/CaptiveNetwork.h> 2. 获取SSID info + (id)fetchSSIDInfo { NSA ...
- 在C#中调用VBScript和JavaScript等脚本的实现
在C#中调用VBScript.JavaScript等脚本的实现 作者:郑佐 2004-04-26 以前在做工作流(workflow)项目的时候,里面有一项就是在用户制定流程定义时可以编写脚本来控制活动 ...
- IIS Express 及 vs2008下使用IIS Express
介绍 IIS Express 开发 ASP.NET 的应用程序是我的主要工作.当然我会选择最适合的开发环境.客户多属于企业用户,我的开发的选择,多半是 ASP.NET Web Application ...
- img图片底部出现莫名的下边距问题
谷歌中这样是解释的: 图片底部的空隙实际上涉及行内元素的布局模型,图片默认的垂直对齐方式是基线,而基线的位置是与字体相关的.所以在某些时候,图片底部的空隙可能是 2px,而有时可能是 4px 或更多. ...
- 旨在脱离后端环境的前端开发套件 - IDT之Server篇
IDT,一个基于Nodejs的,旨在脱离后端环境的前端开发套件,目的就是能让前端开发完全脱离后端的环境,无论后端是什么模板引擎(主流),都能应付自如. IDT主要包括两大部分:Server + Bui ...