p1530 Fractions to Decimals
将余数记录下来,如果余数相同,那么商的下一位也相同。
#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的更多相关文章
- 洛谷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 2.4】Fractions to Decimals(分数转小数)
题意:给你N/D的分数,让你输出等价的小数,如果是循环小数,用括号把循环节包起来.如果是整数,后面保留一位小数.每行最多输出76个字符. 题解:模拟除法,如果余数是第二次出现,则代表第一次出现的位置到 ...
- USACO Section 2.4: Fractions to Decimals
乍看题目感觉有难度,实际分析后其实是道简单题 /* ID: yingzho1 LANG: C++ TASK: fracdec */ #include <iostream> #include ...
- What Is Mathematics?
What Is Mathematics? The National Council of Teachers of Mathematics (NCTM), the world's largest org ...
- 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 ...
- 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 ...
- 模拟 --- hdu 12878 : Fun With Fractions
Fun With Fractions Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit ...
随机推荐
- makefile如果没有符合的显式规则将会使用隐式规则
举例: 当前目录下有个Makefile和jello.c文件,其中有这样的规则jello.o:%.c %.h Makefile (静态模式规则),表明的含义为:要生成的jello.o目标依赖jello. ...
- github帐户和仓库的创建
sign up is registration and sign in is logging in for "in" is to enter an existing account ...
- 如何在gvim中安装autoproto自动显示函数原型
cankao: http://www.vim.org/scripts/script.php?script_id=1553 注意, 在gvim中执行的命令, :foo和:!foo 的区别, 跟vim一样 ...
- HDU 3506 Monkey Party(区间DP)题解
题意:有n个石堆排成环,每次能合并相邻的两堆石头变成新石堆,代价为新石堆石子数,问最少的总代价是多少 思路:先看没排成环之前怎么做:用dp[i][j]表示合并i到j所需的最小代价,那么dp[i][j] ...
- svn强制commit写log
https://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-howto-minlogmsgsize.html Force users to ent ...
- Linux下使用wget下载FTP服务器文件
wget -nH -m --ftp-user=your_username --ftp-password=your_password ftp://your_ftp_host/* 使用命令下载ftp上的文 ...
- Images之Dockerfile中的命令2
COPY COPY has two forms: COPY [--chown=<user>:<group>] <src>... <dest> COPY ...
- EFI环境下的Ubuntu&Win10双系统安装
因为是win10是EFI启动的,所以网上的easyBCD方法就不可以用了,这里用到的不是ultraiso软碟通,用的哪个忘了 不过只要能写入U盘做成启动盘就ok 具体参考的是https://blog. ...
- [luogu]P1852跳跳棋
题目重点是每次不能跳过两个棋子 即对于每一个棋子的状态(a,b,c) (a<b<c) 最多有两种移动的方式 1.中间往两边跳 (a,b,c)-->(2b-a,a,c)或(a,c,2b ...
- HttpUrlConnection底层实现和关于java host绑定ip即时生效的设置及分析
最近有个需求需要对于获取URL页面进行host绑定并且立即生效,在java里面实现可以用代理服务器来实现:因为在测试环境下可能需要通过绑定来访问测试环境的应用实现代码如下: public static ...