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格(网上都这么说,似乎是个 ...
随机推荐
- 【Recover Binary Search Tree】cpp
题目: Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without chan ...
- hdu 1301 Jungle Roads 最小生成树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 The Head Elder of the tropical island of Lagrish ...
- BZOJ1500 维修数列
AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=1500 [前言] 据说没打这题就相当于没打过Splay,这题简直就是让你内心崩溃的... 这 ...
- Notes on the Dirichlet Distribution and Dirichlet Process
Notes on the Dirichlet Distribution and Dirichlet Process In [3]: %matplotlib inline Note: I wrote ...
- 在C语言中嵌入汇编语言
TMS320C28x编译器允许在C程序中嵌入汇编指令,通过下面声明实现: asm(“assembler text”); 其中assembler text指汇编代码.asm指令一般用来处理C/C++语句 ...
- Topcoder 多校T-shirt场
盗用名字:C题题目都没看懂, B:You are given a long long n. Return the largest divisor of n that is a perfect squa ...
- Sqli-labs less 47
Less-47 本关的sql语句为 $sql = "SELECT * FROM users ORDER BY '$id'"; 将id变为字符型,因此根据我们上述提到的知识,我 ...
- POJ 1995
#include <iostream> using namespace std; long long power(long long a, long long b, long long m ...
- Peer certificate cannot be authenticated with known CA certificates.
I was trying to post to a webservice and was getting the 60 error code: Peer certificate cannot be a ...
- lightoj 1397 - Sudoku Solver
思路:每次找出可能情况最少的位置枚举可能情况!!! poj2676和这题一样不过poj数据比较水,很容易过. 代码如下: #include<iostream> #include<cs ...