将余数记录下来,如果余数相同,那么商的下一位也相同。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF,mod=;
int vst[SZ]; string work(int n,int d)
{
if(n==)return ".0";
else
{
memset(vst,-,sizeof(vst));
string str=".";
int res,rem;
vst[n]=;
for(int i=;;++i)
{
n*=;
str+=n/d+'';
n=n%d;
//cout<<i<<" "<<n<<endl;
if(vst[n]!=-)
{
//cout<<vst[n]<<" "<<i<<endl;
str=str.substr(,vst[n]+)+"("+str.substr(vst[n]+,i-vst[n])+")";
break;
}
vst[n]=i;
if(n==)break;
}
return str;
}
} string toStr(int x)
{
if(x==)return "";
string str="";
for(;x;)
{
str=(char)(x%+'')+str;
x/=;
}
return str;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
//cin>>casenum;
//for(lon time=1;time<=casenum;++time)
{
int n,d;
cin>>n>>d;
string res=toStr(n/d)+work(n%d,d);
for(int i=;i<res.size();++i)
{
if(i%==&&i)cout<<endl;
cout<<res[i];
}
//cout<<res<<endl;
}
return ;
}

p1530 Fractions to Decimals的更多相关文章

  1. 洛谷P1530 分数化小数 Fractions to Decimals

    P1530 分数化小数 Fractions to Decimals 103通过 348提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目 ...

  2. Luogu P1530 分数化小数 Fractions to Decimals(模拟)

    P1530 分数化小数 Fractions to Decimals 题意 题目描述 写一个程序,输入一个形如\(N/D\)的分数(\(N\)是分子,\(D\)是分母),输出它的小数形式.如果小数有循环 ...

  3. YTU 1439: 2.4.5 Fractions to Decimals 分数化小数

    1439: 2.4.5 Fractions to Decimals 分数化小数 时间限制: 1 Sec  内存限制: 64 MB 提交: 194  解决: 13 题目描述 写一个程序,输入一个形如N/ ...

  4. 【USACO 2.4】Fractions to Decimals(分数转小数)

    题意:给你N/D的分数,让你输出等价的小数,如果是循环小数,用括号把循环节包起来.如果是整数,后面保留一位小数.每行最多输出76个字符. 题解:模拟除法,如果余数是第二次出现,则代表第一次出现的位置到 ...

  5. USACO Section 2.4: Fractions to Decimals

    乍看题目感觉有难度,实际分析后其实是道简单题 /* ID: yingzho1 LANG: C++ TASK: fracdec */ #include <iostream> #include ...

  6. What Is Mathematics?

    What Is Mathematics? The National Council of Teachers of Mathematics (NCTM), the world's largest org ...

  7. Codeforces Round #384 (Div. 2) C. Vladik and fractions(构造题)

    传送门 Description Vladik and Chloe decided to determine who of them is better at math. Vladik claimed ...

  8. Codeforces Round #232 (Div. 2) D. On Sum of Fractions

    D. On Sum of Fractions Let's assume that v(n) is the largest prime number, that does not exceed n; u ...

  9. 模拟 --- hdu 12878 : Fun With Fractions

    Fun With Fractions Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit ...

随机推荐

  1. myeclise中创建maven web程序

    myeclipse自带了许多插件,因此使用频率很高,但是对maven框架下web程序似乎不是很好的支持,每次创建web程序总是会报一大堆的异常,因此特此记录一下如何在myeclipse下创建一个web ...

  2. EXCEL 基本函数

    案例2:修改非法日期 TODAY(),显示今天日期,数据格式是日期,如果是常规,就是数字. EXCEL 起始日期,1900/1/1是第一天 日期输入方式要正确 时间数据格式  1:00:00  = 1 ...

  3. 3. Elements of a Test Plan

    https://jmeter.apache.org/usermanual/test_plan.html This section describes the different parts of a ...

  4. Win32汇编学习(3):简单的窗口

    这次我们将写一个 Windows 程序,它会在桌面显示一个标准的窗口,以此根据代码来学习如何创建一个简单的窗口. 理论: Windows 程序中,在写图形用户界面时需要调用大量的标准 Windows ...

  5. 160CrackMe练手 001

    peid判断无壳,打开输入伪码注册,根据报错od查找字符串 接下来定位到字符串周边代码 0042FA15 |. 8D55 F0 lea edx,[local.4] 0042FA18 |. 8B83 D ...

  6. 【原理、命令】Git基本原理、与Svn的区别、命令

    一.Git是什么? Git是目前世界上最先进的分布式版本控制系统.工作原理 / 流程:Workspace:工作区Index / Stage:暂存区Repository:仓库区(或本地仓库)Remote ...

  7. (转载)C#:Form1_Load()不被执行的三个解决方法

    我的第一个c#练习程序,果然又出现问题了...在Form1_Load() not work.估计我的人品又出现问题了. 下面实现的功能很简单,就是声明一个label1然后,把它初始化赋值为hello, ...

  8. 【转载】谈谈自己对REST、SOA、SOAP、RPC、ICE、ESB、BPM知识汇总及理解

    转载自:https://blog.csdn.net/tantexian/article/details/48196453 SOA: 维基百科解释:SOA:面向服务的软件架构(Service Orien ...

  9. js实现类型jq的dom加载完成

    有时候我们只想在 dom 加载完成后运行 js ,而不是等所有图片加载完成.所以不需要 onload , onload 会加载图片等其他媒体.很消耗时间. 原:http://blog.csdn.net ...

  10. 【译】第4节---简单的Code First示例

    原文地址:http://www.entityframeworktutorial.net/code-first/simple-code-first-example.aspx 假设我们要为XYZ学校创建一 ...