zoukankan      html  css  js  c++  java
  • Fractal

     Fractal

    时间限制:1000ms
    单点时限:1000ms
    内存限制:256MB

    描述

    This is the logo of PKUACM 2016. More specifically, the logo is generated as follows:

    1. Put four points A0(0,0), B0(0,1), C0(1,1), D0(1,0) on a cartesian coordinate system.

    2. Link A0B0, B0C0, C0D0, D0A0 separately, forming square A0B0C0D0.

    3. Assume we have already generated square AiBiCiDi, then square Ai+1Bi+1Ci+1Di+1 is generated by linking the midpoints of AiBi, BiCi, CiDi and DiAi successively.

    4. Repeat step three 1000 times.

    Now the designer decides to add a vertical line x=k to this logo( 0<= k < 0.5, and for k, there will be at most 8 digits after the decimal point). He wants to know the number of common points between the new line and the original logo.

    输入

    In the first line there’s an integer T( T < 10,000), indicating the number of test cases.

    Then T lines follow, each describing a test case. Each line contains an float number k, meaning that you should calculate the number of common points between line x = k and the logo.

    输出

    For each test case, print a line containing one integer indicating the answer. If there are infinity common points, print -1.

    样例输入
    3
    0.375
    0.001
    0.478
    样例输出
    -1
    4
    20
    题意: 在一个坐标系里有如图图像,问当直线x=k与图像交点有多少,如果是无数的话输出-1
     1 #include <iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<math.h>
     5 #include<algorithm>
     6 
     7 using namespace std;
     8 
     9 #define N 1100
    10 #define INF 0x3f3f3f3f
    11 
    12 int main()
    13 {
    14     int t;
    15     double x;
    16     scanf("%d", &t);
    17     double c = 0.5;
    18     double a[N] = {0};
    19     int b[N] = {0};
    20     for(int i = 1; i < 1000; i++)
    21     {
    22         a[i] = c/2 + a[i-1];
    23         b[i] = b[i-1] + 4;
    24         c /= 2;
    25     }
    26     while(t--)
    27     {
    28         scanf("%lf", &x);
    29         for(int i = 0; i < 1000; i++)
    30         {
    31             if(fabs(a[i]-x) < 0.00000000000001)
    32             {
    33                 printf("-1
    ");
    34                 break;
    35             }
    36             else if(x < a[i])
    37             {
    38                 printf("%d
    ", b[i]);
    39                 break;
    40             }
    41         }
    42     }
    43     return 0;
    44 }
  • 相关阅读:
    spring websocket 记录
    mysql-enum
    再问jvm内存管理
    video相关参数、操作和事件
    监听页面关闭和刷新的总结
    VUE路由新页面打开的方法总结
    VUE的一个数据绑定与页面刷新相关的bug
    element-ui笔记
    Vue笔记(props和 mounted)
    Python总结(二)
  • 原文地址:https://www.cnblogs.com/Tinamei/p/4831373.html
Copyright © 2011-2022 走看看