题意:输入整数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【模拟】的更多相关文章

  1. UVa 202 Repeating Decimals(抽屉原理)

    Repeating Decimals 紫书第3章,这哪是模拟啊,这是数论题啊 [题目链接]Repeating Decimals [题目类型]抽屉原理 &题解: n除以m的余数只能是0~m-1, ...

  2. UVa 202 - Repeating Decimals

    给你两个数,问你他们相除是多少,有无限循环就把循环体括号括起来 模拟除法运算 把每一次的被除数记下,当有被除数相同时第一个循环就在他们之间. 要注意50个数之后要省略号...每一次输出之后多打一个回车 ...

  3. uva 202(Repeating Decimals UVA - 202)

    题目大意 计算循环小数的位数,并且按照格式输出 怎么做 一句话攻略算法核心在于a=a%b*10,用第一个数组记录被除数然后用第二个数组来记录a/b的位数.然后用第三个数组记录每一个被除数出现的位置好去 ...

  4. 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 ...

  5. Repeating Decimals UVA - 202

    The / repeats indefinitely with no intervening digits. In fact, the decimal expansion of every ratio ...

  6. 【习题 3-8 UVA - 202】Repeating Decimals

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 余数出现循环节. 就代表出现了循环小数. [代码] #include <bits/stdc++.h> using nam ...

  7. Repeating Decimals UVA - 202---求循环部分

    原题链接:https://vjudge.net/problem/UVA-202 题意:求一个数除以一个数商,如果有重复的数字(循环小数),输出,如果没有,输出前50位. 题解:这个题一开始考虑的是一个 ...

  8. UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  9. UVA 1156 - Pixel Shuffle(模拟+置换)

    UVA 1156 - Pixel Shuffle 题目链接 题意:依据题目中的变换方式,给定一串变换方式,问须要运行几次才干回复原图像 思路:这题恶心的一比,先模拟求出一次变换后的相应的矩阵,然后对该 ...

随机推荐

  1. Brute force Attack

    1 Introduction A common threat that webdevelopers face is a password-guessing attack known as a brut ...

  2. 操作系统 之 哈希表 Linux 内核 应用浅析

    1.基本概念         散列表(Hash  table.也叫哈希表).是依据关键码值(Key  value)而直接进行訪问的数据结构. 也就是说,它通过把关键码值映射到表中一个位置来訪问记录.以 ...

  3. 去除iframe滚动条

    主页面的IFRAME中添加:scrolling="yes" 子页面程序代码: 让竖条消失: <body style='overflow:scroll;overflow-x:a ...

  4. [JZOJ NOIP2018模拟10.21]

    考试之前我刚刚领略到了特判的重要性,没想到T2的两个子任务还是写挂了,丢了20分 考试的感觉不行,一路打的都是暴力,正解的思路想到一半就断了推不下去 T1:逛公园 题目链接: https://jzoj ...

  5. Django shortcut functions

    django.shortcuts package提供提供帮助类和函数可以更便捷的操作MVC中的每一部分,包含: render(request, template_name,[dictionary],[ ...

  6. 由ubuntu装好想到的

    这篇不是技术文,有点唠叨的总结.不喜勿喷. 最近开始全面学ubuntu,一翻书回忆起本科没选但是去听了的Linux.当时看的还是楚广明的fedora教程,这多年过去综合很多人的说 法,fedora不稳 ...

  7. (转载) Android开发mac /dev/kvm is not found

    Android开发mac /dev/kvm is not found 标签: KVMAndroid开发KVM is not found芒果Android芒果iOS 2016-10-29 16:31 2 ...

  8. Glide中的回调:targets

    Glide隐藏了一大推复杂的在后台的场景,Glide做了所有的网络请求和处理在后台线程中,准备好了切回到ui线程后更新ImageView. 假设ImageView不再是图像的最后一步.我们只要Bitm ...

  9. php面向对象的基础:OOP的常量

    常量(constant) 用来表示不会改变的值.对于从该类实例化的任何对象来说,常量值在这些对象的整个生命周期中都保持不变. class Computer{ const PI=3.1415926; } ...

  10. 待解决问题 oc

    读书破万卷 Associated Object hash实现 Dynamic Method Resolution Message Forwarding forwardingTargetForSelec ...