zoukankan      html  css  js  c++  java
  • CF 900B

    CF 900B
        Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
     

    Description

    现有一式子 a / b. 你需要找出数字 c 在小数点后第一次出现的位置

    Input

    输入包含三个整数 a, b, c (1 ≤ a < b ≤ 105, 0 ≤ c ≤ 9).

    Output

    输出数字 c 第一次在小数点后出现的位置,如果 c 不在小数点后出现输出 -1

    Sample Input

    Input
    1 2 0
    
    Output
    2
    
    Input
    2 3 7
    
    Output
    -1

    Hint

    第一组样例 : 1 / 2 = 0.5000(0) 出现在第二个位置

    第二组样例 : 2 / 3 = 0.6666(6) 7 没有出现,输出 -1

    本题主要有两个易错点,一是不要认为只寻找小数点后六位,我是开到了小数点后1000位。二是double的精度问题,因为double存储格式的问题,存储的小数是不精确的,所以避免小数的运算,转为整数的运算。

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<deque>
    #include<iostream>
    using namespace std;
    const int INF=0x3f3f3f3f;
    const int N=200;
    int main()
    {
        int i,p,j;
        int a,b,c,flag=0;
        scanf("%d%d%d",&a,&b,&c);
        for(i=0; i<=10000; i++)
        {
            if(a<b&&flag==0)
                flag=i+1;
            if(a<b)
            {
                a*=10;
                p=a/b;
                if(p==c&&flag!=0)
                    break;
                a=a%b;
            }
            else
            {
                a=a%b;
            }
    
        }
        if(i<=1000)
            printf("%d
    ",i+2-flag);
        else
            printf("-1
    ");
        return 0;
    }
  • 相关阅读:
    UITableView学习笔记
    IOS基础之设置APP的名字、设置图标、添加等待加载时的图片
    UIScrollView,UIPageControl
    UIPickerView基本用法
    最大公约数和最小公倍数
    快速幂、快速乘
    素数筛
    最小生成树
    BZOJ1070 [SCOI2007]修车
    BZOJ1109 [POI2007]堆积木Klo
  • 原文地址:https://www.cnblogs.com/daybreaking/p/9323246.html
Copyright © 2011-2022 走看看