zoukankan      html  css  js  c++  java
  • 9.3.1 Snail’s trouble

    Snail’s trouble

    Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 48 Accepted Submission(s): 32

    Problem Description
    Once upon a time, there was a poor snail. Every day, it tried very hard to crawl forward, while there was a keeper who’d like to maltreat this poor little snail. The snail was crawling on a one-meter rubber band at first, and it can move on k cm every minute. But after that, the keeper stretches the rubber band quickly, and it would be elongated one meter, during that the distances ratio between the snail and the two endpoints remain unchanged. In the next minute, little snail tried to keep moving forward again.
    “Can I finally get to the endpoint?”
    The snail often asked himself such a question because he was afraid he would never succeed. Now, we hope you can tell this poor snail when he would reach the endpoint.
     

    Input
    Every line of the input contains an integer number k, indicating that the snail moved forward k cm every minute. (5 <= k <= 100)
     

    Output
    Output an integer t, indicating that the snail doesn’t get to the endpoint until t-1 minutes later, while t minutes later, it finally succeed.
     

    Sample Input
    10
    100
     

    Sample Output
    12367
    1

    思路:看懂题就对了啊。。

    另外前几项打一下表,快一点

     1 /*
     2 Author:wuhuajun
     3 */
     4 #include <cmath>
     5 #include <cstdio>
     6 #include <algorithm>
     7 #include <cstring>
     8 #include <string>
     9 #include <cstdlib>
    10 using namespace std;
    11 
    12 typedef long long ll;
    13 typedef double dd;
    14 const int maxn=210;
    15 const dd eps=1E-10;
    16 dd sum;
    17 int n;
    18 
    19 int dblcmp(dd a)
    20 {
    21     if (fabs(a)<eps)
    22         return 0;
    23     if (a>0)
    24         return 1;
    25     return -1;
    26 }
    27 
    28 void close()
    29 {
    30 exit(0);
    31 }
    32 
    33 
    34 void init()
    35 {
    36     while (scanf("%d",&n)!=EOF)
    37     {
    38         if (n==5)
    39         {
    40             printf("272400600
    ");
    41             continue;
    42         }
    43         if (n==6)
    44         {
    45             printf("9717617
    ");
    46             continue;
    47         }
    48         sum=-100;
    49         for (int i=1;;i++)
    50         {
    51             sum+=1.0*n/i;
    52             if (dblcmp(sum)>=0)
    53             {
    54                 printf("%d
    ",i);
    55                 break;
    56             }
    57         }
    58     }
    59 }
    60 
    61 int main ()
    62 {
    63     init();
    64     close();
    65     return 0;
    66 }
  • 相关阅读:
    MySQL常用维护管理工具 枫
    sql触发器 枫
    MySQL函数大全 枫
    使用Cscope阅读Linux源码 枫
    ASP.NET文件下载,直接向客户端输出文件 枫
    网站设计数据库集群和数据库垂直分割,水平分割,库表散列 枫
    西点成品分类 枫
    asp函数列表 枫
    [笔记]一道C语言面试题:实现 itoa() 函数
    [笔记]Arduino平台使用US100超声波测距模块的电平模式测距实验
  • 原文地址:https://www.cnblogs.com/cssystem/p/3335197.html
Copyright © 2011-2022 走看看