Repeating Decimals

UVA - 202

题目传送门

解决方法:模拟一下除法,及时记录余数,当一个余数第二次出现时证明开始循环

AC代码

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
int yushu[maxn];
int shang[maxn];
int wei[maxn];
int main()
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int n,m;int cnt=0;while(scanf("%d %d",&n,&m)!=EOF){int k=n;ms(yushu);ms(shang);ms(wei);int count=0;shang[count++]=n/m;n=n%m;while(!wei[n]&&n){wei[n]=count;yushu[count]=n;shang[count++]=n*10/m;n=n*10%m;}printf("%d/%d = %d.",k,m,shang[0]);int i;for(i=1;i<count&&i<=50;i++){if(yushu[i]==n&&n)printf("(");printf("%d",shang[i]);}if(n==0)printf("(0");if(count>50)printf("...");printf(")\n");printf("   %d = number of digits in repeating cycle\n\n",!n?1:count-wei[n]);}return 0;
}

UVA - 202 Repeating Decimals相关推荐

  1. UVa 202 Repeating Decimals

    计算循环小数的循环节 输入整数a和b(0<=a<=3000,1<=b<=3000),输出a/b的循环小数表示以及循环节长度. 例如,a=5,b=43,小数表示为0.(11627 ...

  2. UVa 202 - Repeating Decimals —— 分数循环节

    题目:计算分数的循环节. https://vjudge.net/contest/227853#problem/C 分析:数论,组合. n除以m的余数只能是0~m-1,根据抽屉原则,当计算m+1次时至少 ...

  3. Repeating Decimals (计算循环小数)

    //计算循环小数,并找出循环节以及循环节的长度,最后输出时若循环节大于50最后输出省略号. //求循环小数,记录被除数,若被除数相同了则证明循环了. //注意:即使是循环小数,但可能并不是从第一位小数 ...

  4. K - Repeating Decimals(循环小数)

    题目描述 The decimal expansion of the fraction 1/33 is 0.03, where the 03 is used to indicate that the c ...

  5. π-Algorithmist分类题目(3)

    原题网站:Algorithmist,http://www.algorithmist.com/index.php/Main_Page π-Algorithmist分类题目(3) Probability ...

  6. 紫书《算法竞赛入门经典》

    紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...

  7. UVa Online Judge 工具網站

    UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...

  8. WaWa的奇妙冒险(第一周集训自闭现场)

    第一周周记 (一)例题记录 A-Download Manager (水题) HDU - 3233 Input Output Sample Input Sample Output 理解 AC代码 B-J ...

  9. 算法竞赛入门经典(第二版)第三章习题

    声明:作者水平有限,只是会基础C语言的小菜,C++还未入门.作者仅根据算法竞赛入门经典(第二版)书上第三章习题所述题意而编写,并未严格按照原题的输入输出编写,代码仅经过个人测试(OJ网站太慢了).代码 ...

最新文章

  1. Theano - Numpy 新手
  2. 【学习笔记】人类为什么最终选择了芯片
  3. 84. Largest Rectangle in Histogram
  4. spss回归分析_回归分析中的简单斜率检验:用SPSS或jamovi实现
  5. C++ STL学习笔记 : 2. unordered map 容器
  6. Java微服务篇2——SpringCloud
  7. go java jsonrpc_使用golang 实现JSON-RPC2.0
  8. 微型计算机控制系统常用报警方式,微型计算机控制技术复习资料.docx
  9. could not read data from '/Users/xxxx/myapp-Info.plist'
  10. python 学习笔记 (核心)
  11. 允许局域网内其他主机访问本地MySql数据库
  12. 经典图书样章试读介绍
  13. Android中ListView复用导致布局错乱的解决方案
  14. 王者峡谷一呼百应,弹幕“666”,背后都离不开长连接,如何实现千万级高性能的长连接网关?...
  15. 33个神经网络训练技巧
  16. mac使用vscode
  17. foxmail邮箱修改服务器,foxmail基本设置方法.foxmail使用技巧
  18. 采购要管好供应商,这几个坑勿踩
  19. 特征选择(模型输入参数的分析选择)方法汇总
  20. [导入]discuz!NT整合经验总结

热门文章

  1. React之state总结
  2. BugkuCTF-MISC题三色绘恋
  3. oracle表空间如何压缩,Oracle里表空间的压缩
  4. mysql免安装如何改密码_mysql免安装版配置与修改密码的教程
  5. python编程类型_Python 基础编程 数据类型(一)
  6. cad常用字体包_CAD制图初学入门如何学好CAD?CAD大神总结5点诀窍,必须收藏
  7. 可选版本 安装软件_【Linux软件】在Deepin系统下安装LibreOffice 6.1.4版本的方法
  8. php枚举mysql,小技巧:取得MYSQL中ENUM(枚举)列的全部可能值。-PHP教程,PHP应用...
  9. labview利用簇模拟汽车控制_在LabVIEW应用程序中何时应采用面向对象技术 (翻译)...
  10. java web 集成dom4j_[JavaWeb基础] 031.dom4j写入xml的方法