uva 202(Repeating Decimals UVA - 202)
题目大意
计算循环小数的位数,并且按照格式输出
怎么做
一句话攻略算法核心在于a=a%b*10,用第一个数组记录被除数然后用第二个数组来记录a/b的位数。然后用第三个数组记录每一个被除数出现的位置好去寻找循环节的位置。
我的代码(算法还是借鉴)
#include <iostream>
#include <cstring>
using namespace std;
int ar[300000];
int re[300000];
int lc[300000];
int main()
{
int a,b;
while(cin>>a>>b)
{
int a1=a;int b1=b;
int now=1;int ck;
ck=a/b;
a=a%b*10;
memset(re,0,sizeof(re));
while(re[a]==0)
{
re[a]=1;
lc[a]=now;//这个地方真的非常非常的厉害,第一遍看都没有看懂,实际上这有点预处理记录的感觉
ar[now]=a/b;
now++;
a=a%b*10;
}
if(ck<0)
printf("%d/%d = 0.",a1,b1);
else
printf("%d/%d = %d.",a1,b1,ck);
if(now-lc[a]==0)
{
for(int i=1;i<lc[a];i++)
cout<<ar[i];
cout<<"(0)\n";
}
else
{
for(int i=1;i<lc[a];i++)
cout<<ar[i];
cout<<"(";
if(now-lc[a]<50)
for(int i=lc[a];i<now;i++)
cout<<ar[i];
else
{
for(int i=lc[a];i<lc[a]+50;i++)
cout<<ar[i];
cout<<"...";
}
cout<<")\n";
cout<<" "<<now-lc[a]<<" = number of digits in repeating cycle\n\n";
}
}
return 0;
}
uva 202(Repeating Decimals UVA - 202)的更多相关文章
- UVa 202 Repeating Decimals(抽屉原理)
Repeating Decimals 紫书第3章,这哪是模拟啊,这是数论题啊 [题目链接]Repeating Decimals [题目类型]抽屉原理 &题解: n除以m的余数只能是0~m-1, ...
- UVa 202 - Repeating Decimals
给你两个数,问你他们相除是多少,有无限循环就把循环体括号括起来 模拟除法运算 把每一次的被除数记下,当有被除数相同时第一个循环就在他们之间. 要注意50个数之后要省略号...每一次输出之后多打一个回车 ...
- Repeating Decimals UVA - 202
The / repeats indefinitely with no intervening digits. In fact, the decimal expansion of every ratio ...
- UVa 202 Repeating Decimals【模拟】
题意:输入整数a和b,输出a/b的循环小数以及循环节的长度 学习的这一篇 http://blog.csdn.net/mobius_strip/article/details/39870555 因为n% ...
- 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---求循环部分
原题链接:https://vjudge.net/problem/UVA-202 题意:求一个数除以一个数商,如果有重复的数字(循环小数),输出,如果没有,输出前50位. 题解:这个题一开始考虑的是一个 ...
- 【习题 3-8 UVA - 202】Repeating Decimals
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 余数出现循环节. 就代表出现了循环小数. [代码] #include <bits/stdc++.h> using nam ...
- UVa 10192 - Vacation & UVa 10066 The Twin Towers ( LCS 最长公共子串)
链接:UVa 10192 题意:给定两个字符串.求最长公共子串的长度 思路:这个是最长公共子串的直接应用 #include<stdio.h> #include<string.h> ...
- UVA 11646 - Athletics Track || UVA 11817 - Tunnelling the Earth 几何
题目大意: 两题几何水题. 1.UVA 11646 - Athletics Track 如图,体育场的跑道一圈400米,其中弯道是两段半径相同的圆弧,已知矩形的长宽比例为a:b,求长和宽的具体数值. ...
随机推荐
- LeetCode 172. Factorial Trailing Zeroes (阶乘末尾零的数量)
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- 深圳MPD大会 讲师演讲稿 2014-10
深圳MPD大会 讲师演讲稿 2014-10 互联网下的蛋-姜志辉.pdf: http://www.t00y.com/file/76704370 俞炜-互联网研发整形术 终于版.pdf: htt ...
- HDU5441 Travel 离线并查集
Travel Problem Description Jack likes to travel around the world, but he doesn’t like to wait. Now, ...
- ios ionic 装平台 笔记
1.安装cnpm : npm install -g cnpm --registry=https://registry.npm.taobao.org 2.An error occurred when I ...
- Codeforces Round #142 (Div. 2)B. T-primes
B. T-primes time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- android电池管理系统
原文:http://www.2cto.com/kf/201408/326462.html 1.概述 随着移动智能设备的快速发屏,电池的续航能力在很大情况下诱导了大众消费者的购买选择,android系统 ...
- 面向画布(Canvas)的JavaScript库
面向画布(Canvas)的JavaScript库 总结 每个库各有特色,根据需求选择 学习要点 面向画布(Canvas)的JavaScript库 EaselJS 是一个封装了 HTML5 画布(C ...
- Dice (HDU 4652)
题面: m 面骰子,求1. 出现n个连续相同的停止 ;2. 出现n个连续不同的停止的期望次数.(n, m ≤ 10^6 ) 解析: 当然要先列式子啦. 用f[i](g[i])表示出现i个连续相同(不相 ...
- 同一个Tomcat下不同项目之间的session共享
最近发现项目运行过程中经常会抛出一个 NullPointerException的异常,经检查发现异常出现的地方是日志模板,一阵检查,正常无误 (把所有记录日志的地方都点了一遍,心里是崩溃的),万念俱灰 ...
- ARM VM安装Linux Diagnostic 2.3扩展
目前创建的Azure Linux虚拟机默认安装的是LAD 3.0,如果客户有特殊需求,可以通过如下方法安装LAD 2.3 1.在Azure Portal卸载LAD 3.0 2.使用Azure Powe ...