zoukankan      html  css  js  c++  java
  • 贪心 POJ 2109 Power of Cryptography

    题目地址:http://poj.org/problem?id=2109

     1 /*
     2     题意:k ^ n = p,求k
     3     1. double + pow:因为double装得下p,k = pow (p, 1 / n);
     4     基础知识: 类型    长度 (bit)    有效数字    绝对值范围
     5             float    32             6~7         10^(-37) ~ 10^38
     6             double    64            15~16        10^(-307) ~ 10^308
     7        long double    128              18~19         10^(-4931) ~ 10 ^ 4932
     8     2. 二分查找:和1类似
     9     3. 取对数:n*ln(k)=ln(p)    ln(k)=ln(p)/n    k=exp(ln(p)/n)
    10 */
    11 #include <cstdio>
    12 #include <iostream>
    13 #include <algorithm>
    14 #include <cstring>
    15 #include <cmath>
    16 #include <string>
    17 #include <map>
    18 #include <queue>
    19 #include <vector>
    20 using namespace std;
    21 
    22 const int MAXN = 1e6 + 10;
    23 const int INF = 0x3f3f3f3f;
    24 
    25 int main(void)        //POJ 2109 Power of Cryptography
    26 {
    27     //freopen ("D.in", "r", stdin);
    28     double n, p, k;
    29 
    30     while (~scanf ("%lf%lf", &n, &p))
    31     {
    32         printf ("%.0f
    ", pow (p, 1 / n));
    33     }
    34 
    35     return 0;
    36 }
    37 
    38 /*
    39 #include <cstdio>
    40 #include <cmath>
    41 #include <algorithm>
    42 #include <iostream>
    43 using namespace std;
    44 
    45 void BinarySearch(int l, int r, double n, double p)
    46 {
    47     int mid;
    48 
    49     while (l <= r)
    50     {
    51         mid = l + (r - l) / 2;
    52         double tmp = pow (mid, n);
    53         if (tmp == p)
    54         {
    55             printf ("%d
    ", mid);    return ;
    56         }
    57         else if (tmp < p)    l = mid + 1;
    58         else    r = mid - 1;
    59     } 
    60 }
    61 
    62 int main(void)
    63 {
    64     //freopen ("D.in", "r", stdin);
    65 
    66     double n, p;
    67 
    68     while (~scanf ("%lf%lf", &n, &p))
    69     {
    70         BinarySearch (1, 1e9, n, p);
    71     }
    72 
    73     return 0;
    74 }
    75 */
    76 
    77 /*
    78 #include <cstdio>
    79 #include <cmath>
    80 #include <algorithm>
    81 #include <iostream>
    82 using namespace std;
    83 
    84 int main(void)        //POJ 2109 Power of Cryptography
    85 {
    86     //freopen ("D.in", "r", stdin);
    87 
    88     double n, p;
    89 
    90     while (~scanf ("%lf%lf", &n, &p))
    91     {
    92         printf ("%.0f
    ", exp (log (p) / n));
    93     }
    94 
    95     return 0;
    96 }
    97 */
    编译人生,运行世界!
  • 相关阅读:
    xcode5.1上真机调试报告No architectures to compile for...的解决办法
    Altium Designer元件库--多单元元器件的制作
    COMS门电路的设计及其优化--以异或门为例
    从器件物理层面看MOSFET的内部结构
    VHDL与Verilog硬件描述语言TestBench的编写
    C语言求解Excel地址转换问题
    数字黑洞求解问题
    计算机显示电池出现问题
    Charles安装
    滑动窗口1——无重复字符的最长字串
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4372429.html
Copyright © 2011-2022 走看看