UVa 202 Repeating Decimals【模拟】
2024-09-05 07:13:16
题意:输入整数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----------
最新文章
- asp.net MVC 应用程序的生命周期
- 通过正则表达式实现简单xml文件解析
- 介绍开源的.net通信框架NetworkComms框架 源码分析(十三)ThreadSafeStream
- dolby逝世:纪念一下
- java ConcurrentModificationException探究
- [转载]推荐不伤眼睛的文字背景色 VS背景色
- 关于easyUI在子页面增加显示tabs的一个问题
- (转)ubuntu下如何查看和设置分辨率
- Mongodb安装和基本命令
- AutoCAD 2014简体中文版官方正式版x86 x64下载,带注册机,永久免费使用
- ORA-12516 TNS监听程序找不到符合协议堆栈要求的可用处理程序
- html中object标签详解
- Customer segmentation – LifeCycle Grids with R(转)
- SQL查询语句优化的实用方法
- 记一次Nginx+Keepalived高可用故障转移
- 微信小程序页面带参数跳转
- jquery对象和DOM对象的相互转换详解
- netty 的 JBoss Marshalling 编码解码
- 【LOJ#10154】选课
- 使用shell脚本监控用户登陆服务器并发送提示信息给微信