zoukankan      html  css  js  c++  java
  • hdoj--2522--A simple problem(数学模拟)

    A simple problem

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 3866    Accepted Submission(s): 1444


    Problem Description
    Zty很痴迷数学问题.。一天,yifenfei出了个数学题想难倒他,让他回答1 / n。但Zty却回答不了^_^. 请大家编程帮助他.
     

    Input
    第一行整数T,表示测试组数。后面T行,每行一个整数 n (1<=|n|<=10^5).
     

    Output
    输出1/n. (是循环小数的,只输出第一个循环节).
     

    Sample Input
    4 2 3 7 168
     

    Sample Output
    0.5 0.3 0.142857 0.005952380
     

    Author
    yifenfei
     

    Source
     

    Recommend
    gaojie   |   We have carefully selected several similar problems for you:  1496 1280 1264 2600 2523


    /*其实这一道题跟一般的数学除法很像,只是真正的小数除法都是在小数点后边,
    但是那样在c语言中是行不通的,所以每一步乘以10来计算,vis标记是否出现过*/
    #include<stdio.h>
    #include<string.h>
    #define 100000+100
    int vis[MAX];
    int main()
    {
    	int yu,t,n;
    	scanf("%d",&t);
    	while(t--)
    	{
    		scanf("%d",&n);
    		if(n==1)
    		{
    			printf("1
    ");
    			continue;
    		}
    		if(n<0)
    		{
    			printf("-");
    			n=-n;
    		}
    		printf("0.");
    		memset(vis,0,sizeof(vis));
    		yu=1,vis[1]=1;
    		while(yu)
    		{
    			yu*=10;
    			printf("%d",yu/10);
    			yu%=10;
    			if(vis[yu])
    			break;
    			vis[yu]=1;
    		}
    		printf("
    ");
    	}
    	return 0;
    }

     
  • 相关阅读:
    Markdown常用语法
    课程及资源链接
    cpa-会计
    高管具备的能力
    JDK并发包-copy
    Guava工具类学习-copy
    java开发注解大全-copy
    Codeforces Round #703 (Div. 2)
    [ABC200E] Minflip Summation
    Codeforces Round #720 (Div. 2)
  • 原文地址:https://www.cnblogs.com/playboy307/p/5273742.html
Copyright © 2011-2022 走看看