ACM pku 1140 解题报告(Expanding Fractions )

acm hnu 10039 Magician (easy) Magician Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB Total submit users: 157, 阅读详情

Expanding Fractions
Time Limit:1000MS  Memory Limit:10000K
Total Submit:555 Accepted:192

Description
In this problem you are to print the decimal expansion of a quotient of two integers. As you well know, the decimal expansions of many integer quotients result in decimal expansions with repeating sequences of digits. You must identify these. You will print the decimal expansion of the integer quotient given, stopping just as the expansion terminates or just as the repeating pattern is to repeat itself for the first time. If there is a repeating pattern, you will say how many of the digits are in the repeating pattern.

Input
There will be multiple input instances, each instance consists of two positive integers on a line. The first integer represents the numerator of the fraction and the second represents the denominator. In this problem, the numerator will always be less than the denominator and the denominator will be less than 1000. Input terminates when numerator and denominator are both zero.

Output
For each input instance, the output should consist of the decimal expansion of the fraction, starting with the decimal point. If the expansion terminates, you should print the complete decimal expansion. If the expansion is infinite, you should print the decimal expansion up to, but not including the digit where the repeated pattern first repeats itself.

For instance, 4/11 = .3636363636..., should be printed as .36. (Note that the shortest repeating pattern should be found. In the above example, 3636 and 363636, among others, are repeating patterns, but the shortest repeating pattern is 36.)

Since some of these expansions may be quite long, multiple line expansions should each contain exactly 50 characters on each line (except the last line, which, of course, may be shorter) - that includes the beginning decimal point.

On the line immediately following the last line of the decimal expansion there should be a line saying either ``This expansion terminates.", or ``The last n digits repeat forever.", where n is the number of digits in the repeating pattern.

Helpful hint: The number of digits before the pattern is repeated will never be more than the value of the denominator.

Sample Input

3 7
345 800
112 990
53 122
0 0 

Sample Output

 .428571
The last 6 digits repeat forever.
.43125
This expansion terminates.
.113
The last 2 digits repeat forever.
.4344262295081967213114754098360655737704918032786
885245901639
The last 60 digits repeat forever.

Source
East Central North America 1994

 


 

真分式除式的原理就是用一个数乘以除数,使被除数被足0后与得到的这个积的差小于除数.然后再用这个差补足0再重复上面的步骤.

判断从那开始循环时,大家是不是会很快地想到用类似字符比较的方法?其实,只要看是不是有和前面得出来的余数相同的余数就可以了!因为余数是会马上被当作被除数来用的,而相同的除数不变,被除数又与前面的相同,自然除得的结果会与前面的重复.太奇妙了~

 if( (i==49)  || ( (i > 51) && ((i+1)%50==0)   )     )printf("/n");   /*关键是这句!可以看出,第一行只有49个数字(因为包括了“.”),而第二行以后就要有50个*/
这个错可找死我了,正是练习了发现问题的能力~

 


 

main()
{
int a ,b ,yushu[1200] ,r ,i ,j;
int find;

scanf("%d%d",&a,&b);

while( a != 0 && b != 0)
{
yushu[0] = a;
printf(".");
i = 1;
find = 0;
 while(1)
 {
 r = yushu[i-1]*10/b;
 yushu[i] = yushu[i-1]*10%b;
 printf("%d",r);

 if(yushu[i]==0)
 {
  find = 2;
  break;
 }

 for( j = 0 ; j < i ; j++)
 {
  if(yushu[j]==yushu[i])
  {
   find = 1;
   break;
  }
 }

 if(find==1 || find==2)break;
 if( (i==49)  || ( (i > 51) && ((i+1)%50==0)   )     )printf("/n");  
 i++;
 }/*inside while*/
 if(find==1)
 {
  printf("/nThe last %d digits repeat forever./n",i-j);
 }else{
  printf("/nThis expansion terminates./n");
 }
scanf("%d%d",&a,&b);

}/*while*/

}/*main*/

 

 

 

 
Fluent后台计算中Journal文件的自动化编写与优化实践 本文深入探讨了Fluent在Linux/Unix环境下进行后台计算时,Journal文件的自动化编写与优化实践。Journal文件作为Fluent后台计算的“灵魂”,是实现仿真流程自动化、保证计算可重复性与准确性的关键。文章从基础脚本骨架搭建、命令简写技巧,到进阶的参数化研究与批量计算实现,提供了详实的实战指南,帮助工程师大幅提升仿真效率。 阅读详情

相关推荐

AlphaFold2算法详解

正文:https://www.nature.com/articles/s41586-021-03819-2 补充文件:https://static-content.springer.com/esm/art%3A10.1038%2Fs41586-021-03819-2/MediaObjects/41586_2021_3819_MOESM1_ESM.pdfhttps://static-content.springer.com/esm/art%3A10.1038%2Fs41586-021-03819-2/Med

Daisy4的博客 1万+

ACM--Expanding Fractions

简略描述:求循环小数的循环节 Sample Input 3 7 345 800 112 990 53 122 0 0 Sample Output .428571 The last 6 digits repeat forever. .43125 This expansion terminates. .113 The last 2 digits repeat

Beyond the max 493

告别误唤醒!S32K3xx低功耗设计避坑指南:Fast Standby模式与WISR寄存器操作详解

本文深入解析了NXP S32K3xx系列MCU在低功耗设计中常见的误唤醒问题,并提供了基于Fast Standby模式的解决方案。文章重点剖析了DCMRWF5寄存器的配置方法、WISR/WISR_64唤醒中断状态寄存器的标志位处理策略,以及如何利用32KB Standby SRAM保存唤醒状态,从而帮助开发者构建稳定可靠的汽车电子低功耗系统。

weixin_29163857的博客 362

1697: Expanding Fractions 循环节

<br />1697: Expanding FractionsResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE3s8192K19151Standard<br />In this problem you are to print the decimal expansion of a quotient of two integers. As you well know, the decimal expansions of many integer quotie

kongming_acm的专栏 483

Abaqus小白必看:用Micromechanics Plugin轻松搞定RVE周期性边界条件(附避坑指南)

本文为Abaqus初学者提供了使用官方Micromechanics Plugin插件高效实现复合材料代表性体积单元分析的完整指南。文章详细讲解了从插件安装、模型准备、周期性边界条件自动设置到结果验证的全流程,并重点分享了处理复杂模型和避免常见错误的实用技巧,帮助用户大幅提升RVE分析效率与准确性。

weixin_28363123的博客 799

如何使用windows搭建一个公网ftp/sftp服务器

在有公网ip的情况下,使用windows系统搭建一个ftp/sftp服务器会带来很多的方便,可以实现远程移动端的一键式访问,对于文件的备份、多设备的共享都十分的方便。然而网上许多的教程都是基于windows自带的iis搭建一个局域网ftp服务器,然而在搭建好后,我想要通过端口映射的方式实现在外网访问时,却发现连接不上的问题,感觉可能是因为windows家庭版的原因导致的。因此在查阅很多资料之后终于找到了一个公网ftp/sftp服务器的搭建方式,实测可用。这里把流程记录一下,做一个备忘录,也方便大家搭建。

weixin_43354138的博客 1万+

UVa 275 - Expanding Fractions

题目:给你一个分数的分子和分母,求出他的循环节。 分析:模拟。根据鸽巢原理,设分母为m则计算中最多有m中不同的余数,所以循环节小于m。 说明:每次记录余数*10在取新的余数即可。 #include #include #include #include #include #include using namespace std; int n,m; int save[1001];

小白菜又菜 1755

技术美术个人笔记(十三)——Houdini金属弯曲模拟

最近接收到使用Houdini自动解算破损/砸坏/扭曲汽车的需求,以此文记录制作金属弯曲自动解算工具时使用的部分节点解析;

小谁的博客 2148

基础题 HOJ 1140 Expanding Fractions

Expanding FractionsMy Tags  (Edit)Source : ACM ICPC East Central North America 1994Time limit : 3 secMemory limit : 32 MSubmitted : 697, Accepted : 259In this problem you are to print the decimal expa

We Can 639

如何把ORCAD 中的修改同步到PADS 中

Generate ECO file(*.eco),eco 文件的默然保存地址是在pads 的。ECO Files (*.eco),接着在文件中找到所生成的eco 文件,找到。再下来是产生eco 文件,先打开old_design.pcb,然后选择。PCB Design 前面的选项选中,意思把当前文件做为原始的比对。安装目录下(可修改eco 文件的保存目录),这里把eco 文件保存。接下来用新生成asc 文件的文件产生新的PCB 文件,新生成。不对新生成的pcb 做任何的修改,直接保存文件,这里把新文件。

智光工作室 993

SAP Fiori Launchpad Tile,UI5 应用,和 PFCG Role 的对应关系

问题:已经看到了SAP Fiori Launchpad上的某个tile,如何反推后台需要配置哪个PFCG Role才能看到该tile? 这个问题是今天一个朋友在微信上问我的。因为我最近忙着学习一个新的SAP产品,所以这个问题也没有时间展开来写,本文就只做概要介绍。 下图是一个Gateway系统上打开的SAP CRM Fiori Launchpad: 如何弄清楚后台用户配置了哪个PFCG Role之后,才能看到Sales Representative(CRM)这个Group下的tile? 既然当前我使用的用

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1520

UVA 275 - Expanding Fractions

与UVA202类似,依旧是抽屉算法,代码只需稍作修改即可实现代码如下:#include &lt;iostream&gt; #include &lt;cstring&gt; #include &lt;cstdlib&gt; using namespace std; int main() { int x[1005],y[1005]; int a,b,n,i; while(ci...

liuxinyu666的博客 794

《测控仪器设计课后习题答案-浦昭邦-王宝光

《测控仪器设计课后习题答案-浦昭邦-王宝光 1.1. 测控仪器的概念是什么? 测控仪器则是利用测量和控制的理论,采用机、电、光各种计量测试原理及控制系统与计算机相结合的一种范围广泛的测量仪器。 1.2. 为什么说测控仪器的发展与科学技术发展密切相关? 仪器仪表的用途和重要性— 遍及国民经济各个部门,深入到人民生活的各个角落,仪器仪表中的计量测试仪器与控制仪器统称为测控仪器,可以说测控仪器的水平是科学技术现代化的重要标志。 仪器仪表的用途: 在机械制造业中:对产品的静态与动态性能测试;加工过程的控制与监测;设

无名何许人的博客 2976

uva 275 Expanding Fractions

题目:给你一个分数的分子和分母,求出他的循环节。 Sample Input 3 7 345 800 112 990 53 122 0 0 Sample Output .428571 The last 6 digits repeat forever. .43125 This expansion terminates. .113 The last

脚踏实地 688

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

acm pku 2234 解题报告(取子问题)

      题目是这样的,两个人玩一种取火柴的游戏,火柴有若干堆,某个人去取时,可以从某一堆中取若干根,谁最后把所有的火柴取完谁就是胜者。接着给出几组数据,对于每一组数据,第一个数 n 为火柴的堆数,接下来的 n 个数据为每一堆火柴的数量,如果最终第一个取火柴的人会获胜,则输出 Yes,否则输出 No。      这显然是一个取子问题,如果这两个人都知道取的策略,我们可以知道结改局在取之前就可以定

zhangwenjun32的专栏 1243

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

UVA 10668 - Expanding Rods(数学+二分)

UVA 10668 - Expanding Rods 题目链接 题意:给定一个铁棒,如图中加热会变成一段圆弧,长度为L′=(1+nc)l,问这时和原来位置的高度之差 思路:画一下图可以很容易推出公式,设圆弧扇形部弧度r,那么可以计算出铁棒长度为lr/sin(r)这个公式在[0, pi/2]是单调递增的,所以可以用二分法去求解 要注意的一点是最后答案计算过程中带入mid,

Remilia's 1549

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

UVa 332 - Rational Numbers from Repeating Fractions

題目:已知一個分數的小數形式和循環節長度,求分數。 分析:數論。利用題目給的公式直接求解即可。             處理過程中直接使用整數計算             然後對分子分母計算約分即可。 說明:發現並沒有讀過多少書╮(╯▽╰)╭。 #include int gcd(int a, int b) { return a%b?gcd(b, a%b):b; } int mai

小白菜又菜 1753

poj 1140 Expanding Fractions 除法模拟

//poj 1140 //sep9 #include using namespace std; int vis[1024]; void solve(int a,int b) { int cnt=0,t=0; memset(vis,-1,sizeof(vis)); vis[a]=cnt++; a*=10; printf("."); while(1){ printf("%d",a/

sepNINE的专栏 657

POJ刷题顺序

POJ从简到难(按照AC数目排序)的列表如下,作为小弱的刷题顺序。大牛们可以看后面倒排的hard表,还有四道题没人拿到first blood. 表格属性依次为:ID,Title, Ratio, AC, Submit1000 A+B Problem 0.55 188072 338977 1004 Financial Management 0.41 58282 140301 1003 Hangov

Super_zhao的博客 2万+

POJ 1140 Expanding Fractions G++ 巧妙

给出分子和分母。求相应的小数形式(给出循环节)。提示:模式重复之前的位数不会超过分母的值。

woniupengpeng的专栏 602

几款windows下的C的编译器

TURBO C在DOS下用,很不方便的,刚从网上搜了一下几款C COMPLIER,与大家分享。试过了,都能下的。lcc-win32http://www.cs.virginia.edu/~lcc-win32/MyTC http://download.zol.com.cn/detail/4/30278.shtmlMiracle C Compilerhttp://www.zdnet.com.

Manio 1万+

PI后面1000000位,吓死人了

Pi to one MILLION decimal places3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 8214808651328230664709384460955058223172535940812848111

Manio 8879

搜索算法全集(pascal)(转载)

『推荐』搜索算法全集(也是特别爽的哦,内部资料!!)搜 索 算 法  搜索算法是利用计算机的高性能来有目的的穷举一个问题的部分或所有的可能情况,从而求出问题的解的一种方法。搜索过程实际上是根据初始条件和扩展规则构造一棵解答树并寻找符合目标状态的节点的过程。所有的搜索算法从其最终的算法实现上来看,都可以划分成两个部分──控制结构和产生系统,而所有的算法的优化和改进主要都是通过修改其控制结构来完成的。

Manio 3037

ACM pku 1067 解题报告(威佐夫博奕(Wythoff Game))

取石子游戏 Time Limit:1000MS  Memory Limit:10000KTotal Submit:2539 Accepted:579 Description有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子;二是可以在两堆中同时取走相同数量的石子。最后把石子全部取完者为胜者。现在给出初始的两堆石子的

Manio 2942

ACM pku 1004 解题报告

Financial Management Time Limit:1000MS  Memory Limit:10000KTotal Submit:14420 Accepted:6246 DescriptionLarry graduated this year and finally has a job. Hes making a lot of money, but somehow never

Manio 2425

ACM pku 1003 解题报告(练习输入输出)

Hangover Time Limit:1000MS  Memory Limit:10000KTotal Submit:12059 Accepted:4808 DescriptionHow far can you make a stack of cards overhang a table? If you have one card, you can create a maximum ov

Manio 2389
上一篇: 马牛的C#学习(第五天)-定义类成员
下一篇: 马牛的C#学习(第六天)-实践!用C#解决汉诺塔问题
manio
博客等级 码龄21年 61粉丝 151原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值