HDU 2522 1/n Hash

哎~~简直是坑爹的setbuf(stdout,NULL),不理解这个函数的机理,结果为杭电贡献了N次的time limit exceed,其实这道题目还是非常简单的,了解了除法的机制以后,就很好做了,注意余数相同时,循环节开始

 

ContractedBlock.gif ExpandedBlockStart.gif View Code
 1 /*
2 * Author:lonelycatcher
3 * problem:hdu 2522
4 * Type:Hash
5 */
6 #include <iostream>
7 #include<stdio.h>
8 #include<string.h>
9 #include<cstdlib>
10 using namespace std;
11 int n;
12 bool Hash[100002];
13 void div(int x)
14 {
15 int left=1;
16 Hash[1]=1;
17 while(left)
18 {
19 left*=10;
20 printf("%d",left/x);
21 left%=x;
22 if(Hash[left])break;
23 Hash[left]=1;
24 }
25 }
26 int main()
27 {
28 int T;
29 scanf("%d",&T);
30 while(T--)
31 {
32 memset(Hash,0,sizeof(Hash));
33 scanf("%d",&n);
34 if(n<0){printf("-");n*=-1;}
35 if(n==1){printf("1\n");continue;}
36 printf("0.");
37 div(n);
38 printf("\n");
39 }
40
41 return 0;
42 }

转载于:https://www.cnblogs.com/lonelycatcher/archive/2011/08/23/2151215.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值