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

#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. 前端 --- 2 css

    一. CSS的几种引入方式 1.行内样式 2.内部样式 写在网页的<head></head>标签对的<style></style>标签对中 3.外部样式 ...

  2. Restful framework【第二篇】APIView

    安装djangorestframework 方式一:pip3 install djangorestframework 方式二:pycharm图形化界面安装 方式三:pycharm命令行下安装(装在当前 ...

  3. CentOS 源码编译安装 Python3

    准备 yum -y install wget gcc make libffi-devel zlib-devel readline-devel bzip2-devel ncurses-devel sql ...

  4. linux基础之网络基础配置

    基础命令:ifconfig/route/netstat,ip/ss,nmcli 一.ifconfig/route/netstat相关命令 1.  ifconfig - configure a netw ...

  5. linux--磁盘及文件系统管理

    磁盘管理 : 主流的磁盘 : 机械式硬盘 常见的有 : U盘, 光盘, 软盘, 硬盘, 磁带机 扇区 : sector 磁道 : track 柱面 : cylinder 磁盘出厂时 : 低级格式化 : ...

  6. PredNet --- Deep Predictive coding networks for video prediction and unsupervised learning --- 论文笔记

    PredNet --- Deep Predictive coding networks for video prediction and unsupervised learning   ICLR 20 ...

  7. MPI之聚合通信-Scatter,Gather,Allgather

    转自:https://blog.csdn.net/sinat_22336563/article/details/70229243 参考:http://mpitutorial.com/tutorials ...

  8. .Net Core 全球化&本地化的使用

    官网文档 nuget地址 创建资源文件 添加资源文件 实施策略 配置本地化 本地化中间件 使用 视图本地化 DataAnnotations 本地化 Make the app's content loc ...

  9. org.springframework.jdbc.UncategorizedSQLException: Error attempting to get column 'alarmGroup' from result set. Cause: java.sql.SQLException: Error

    异常展示: org.springframework.jdbc.UncategorizedSQLException: Error attempting to get column 'alarmGroup ...

  10. js旋转V字俄罗斯方块

    实现效果如图,也就是一个图像的旋转.注意,旋转后的文字是相对应的,而且文字还是立起的.第一次点击时显示,第二次点击时开始旋转.下面是我做这个效果的记录,方法这么差,我也就不说什么了. 先上HTML/C ...