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 题目链接 题意:依据题目中的变换方式,给定一串变换方式,问须要运行几次才干回复原图像 思路:这题恶心的一比,先模拟求出一次变换后的相应的矩阵,然后对该 ...
随机推荐
- 【LeetCode-面试算法经典-Java实现】【168-Excel Sheet Column Title(Excell列标题)】
[168-Excel Sheet Column Title(Excell列标题)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given a positive in ...
- 《Head First 设计模式》学习笔记——适配器模式 + 外观模式
在ADO.NET中.对于我们从数据库中取出的数据都要放到一个DataSet中,无论你是Access的数据库,还是SQL的数据库,或者是Oracle的数据库都要放到DataSet中..NET中并没有提供 ...
- 【LeetCode】Palindrome Partitioning 解题报告
[题目] Given a string s, partition s such that every substring of the partition is a palindrome. Retur ...
- TCP、HTTP协议的RPC
TCP.HTTP协议的RPC 1.1 基于TCP协议的RPC 1.1.1 RPC名词解释 RPC的全称是Remote Process Call,即远程过程调用,RPC的实现包括客户端和服务端,即服务调 ...
- xBIM 实战03 使用WPF技术实现IFC模型的加载与浏览
系列目录 [已更新最新开发文章,点击查看详细] WPF应用程序在底层使用 DirectX ,无论设计复杂的3D图形(这是 DirectX 的特长所在)还是绘制简单的按钮与文本,所有绘图工作都是 ...
- ikbc 时光机 F87 Ctrl 失灵 解决办法
多按几次Fn+PrtSc,直至按键无错位.
- 《剑指offer》数组中出现次数超过一半的数字
一.题目描述 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出 ...
- latex问题总结
1.使 IEEE 的 Latex 杂志(journal)模板(templet)图片标题(caption)居中 由于IEEETran-journal中的默认caption左对齐.加上\usepackag ...
- DNS BIND之dnssec安全介绍
Domain Name System Security Extensions (DNSSEC)DNS安全扩展,是由IETF提供的一系列DNS安全认证的机制(可参考RFC2535).它提供了一种来源鉴定 ...
- 路飞学城Python-Day11
[44.函数-生成器] 需求:有一个列表 [0,1,2,3,4,5,6,7,8,9],对这个列表循环+1 li = [0,1,2,3,4,5,6,7,8,9] li = map(lambda x:x+ ...