UVa 202 Repeating Decimals【模拟】
题意:输入整数a和b,输出a/b的循环小数以及循环节的长度
学习的这一篇
http://blog.csdn.net/mobius_strip/article/details/39870555
因为n%m的余数只可能是0到m-1中的一个,根据抽屉原理,当计算m+1次时至少存在一个余数相同
发现看了题解理解起来也好困难啊,
后来手动画了一下5/7的竖式除法的式子,,理解一些了
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i) typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int vis[maxn],r[maxn],s[maxn]; int main(){
int n,m;
while(cin>>n>>m){
memset(vis,,sizeof(vis));
memset(r,,sizeof(r));
memset(s,,sizeof(s)); int cnt=;
int t=n;
r[cnt++]=n/m;
n=n%m;
while(!vis[n]&&n){
vis[n]=cnt;
s[cnt]=n;//s数组存的是对应的余数
r[cnt++]=n*/m;//r数组存的是对应的商
n=n*%m;
} printf("%d/%d = %d.",t,m,r[]); for(int i=;i<cnt&i<=;i++){
if(s[i]==n&&n) printf("(");
printf("%d",r[i]);
}
if (!n) printf("(0");
if (cnt > ) printf("...");
printf(")\n");
printf(" %d = number of digits in repeating cycle\n\n",!n?:cnt-vis[n]);
}
return ;
}
还得再多画一画----好晕--------------
写模拟写得好难受------------
goooooooooooooo----------
UVa 202 Repeating Decimals【模拟】的更多相关文章
- UVa 202 Repeating Decimals(抽屉原理)
Repeating Decimals 紫书第3章,这哪是模拟啊,这是数论题啊 [题目链接]Repeating Decimals [题目类型]抽屉原理 &题解: n除以m的余数只能是0~m-1, ...
- UVa 202 - Repeating Decimals
给你两个数,问你他们相除是多少,有无限循环就把循环体括号括起来 模拟除法运算 把每一次的被除数记下,当有被除数相同时第一个循环就在他们之间. 要注意50个数之后要省略号...每一次输出之后多打一个回车 ...
- uva 202(Repeating Decimals UVA - 202)
题目大意 计算循环小数的位数,并且按照格式输出 怎么做 一句话攻略算法核心在于a=a%b*10,用第一个数组记录被除数然后用第二个数组来记录a/b的位数.然后用第三个数组记录每一个被除数出现的位置好去 ...
- UVa 202 Repeating Decimals 题解
The decimal expansion of the fraction 1/33 is 0.03, where the 03 is used to indicate that the cycle ...
- Repeating Decimals UVA - 202
The / repeats indefinitely with no intervening digits. In fact, the decimal expansion of every ratio ...
- 【习题 3-8 UVA - 202】Repeating Decimals
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 余数出现循环节. 就代表出现了循环小数. [代码] #include <bits/stdc++.h> using nam ...
- Repeating Decimals UVA - 202---求循环部分
原题链接:https://vjudge.net/problem/UVA-202 题意:求一个数除以一个数商,如果有重复的数字(循环小数),输出,如果没有,输出前50位. 题解:这个题一开始考虑的是一个 ...
- UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVA 1156 - Pixel Shuffle(模拟+置换)
UVA 1156 - Pixel Shuffle 题目链接 题意:依据题目中的变换方式,给定一串变换方式,问须要运行几次才干回复原图像 思路:这题恶心的一比,先模拟求出一次变换后的相应的矩阵,然后对该 ...
随机推荐
- UVA - 10229 Modular Fibonacci 矩阵快速幂
Modular Fibonacci The Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, 21, 3 ...
- hdoj--1260--Tickets(简单dp)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- 搞定ubuntu下环境变量的配置
Ubuntu Linux系统环境变量配置文件: /etc/profile : 在登录时,操作系统定制用户环境时使用的第一个文件 ,此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. ...
- validation-api参数校验
这里针对springboot项目结构 maven添加: <dependency> <groupId>javax.validation</groupId> <a ...
- 关于jsp web项目,jsp页面与servlet数据不同步的解决办法(报错404、405等)即访问.jsp和访问web.xml中注册的/servlet/的区别
报错信息: Type Status Report Message HTTP method GET is not supported by this URL Description The method ...
- [ Docker ] 映射資料夾
- docker run -v <host path>:<container path> - 例如:docker run -v /home/adrian/data:/data ...
- 用js将CheckBox的值存入数据库和将数据库字符串的值转为数组选中CheckBox
Index @{ ViewBag.Title = "测试"; } <script src="~/Scripts/jquery-1.10.2.js"> ...
- Converting Legacy Chrome IPC To Mojo
Converting Legacy Chrome IPC To Mojo Looking for Mojo Documentation? Contents Overview Deciding What ...
- python 之 MRO 异常
今天突然遇到这个异常,先贴两个地址,待有时间写博客 https://www.jianshu.com/p/fea6e0a0cc14 https://makina-corpus.com/blog/meti ...
- python自动化报错
今天使用python.然而遇见了报错.抓狂的一笔.有说path写错的,有说是...网上查到的资料也是很少.后来突然发现,页面上我暂时能看到的元素可以定位并进行操作.看不到的无法进行...ps此时我没有 ...