double精度强悍!Pow函数威武!EXP够神!
-
#include <stdio.h>
-
#include <math.h>
-
-
int main()
-
{
-
double m, p;
-
while(scanf("%lf%lf", &m, &p) != EOF)
-
{
-
printf("%.0lfn", pow(p, 1/m));
-
}
-
return 0;
-
}
-
-------------------------------------------------------
-
-
-
下面是我的错误代码:
-
没加二分是TLE,加了二分就WA.
-
-
#include <stdio.h>
-
#include <math.h>
-
-
#define MAX 120
-
-
int p[MAX];
-
-
int Len(double x)
-
{
-
int cnt = 0;
-
while(x - 1 >= 0)
-
{
-
cnt++;
-
x /= 10;
-
}
-
return cnt;
-
}
-
-
int main()
-
{
-
int n, i, lenp, k, j, lent, z, tp, r, midd, x, y;
-
char c;
-
double t, sub;
-
freopen("in.txt", "r", stdin);
-
while(scanf("%d", &n) != EOF)
-
{
-
i = 0;
-
k = 1000000000;
-
getchar();
-
while((c = getchar()) != 'n')
-
{
-
if (c == EOF)
-
{
-
break;
-
}
-
p[i++] = c - '0';
-
}
-
lenp = i;
-
x = 1;
-
y = k;
-
while (x < y)
-
{
-
midd = x + (y - x) / 2;
-
t = ceil(t = pow((double)midd, (double)n));
-
if ((lent = Len(t)) == lenp)
-
{
-
if (lent > 16)
-
{
-
j = lenp - 16;
-
t = ceil(t /= pow(10, j));
-
j = 15;
-
r = 16;
-
}
-
else
-
{
-
j = lent - 1;
-
r = lenp;
-
}
-
z = (int)(t / pow(10, j));
-
//printf("%d", z);
-
tp = 0;
-
while (tp < lenp && p[tp] == z)
-
{
-
sub = pow(10, j)*z;
-
tp++;
-
j--;
-
t = ceil(t -= sub);
-
z = (int)(t / pow(10, j));
-
}
-
if (tp == r)
-
{
-
printf("%dn", midd);
-
break;
-
}
-
if (z > p[tp])
-
{
-
y = midd;
-
}
-
else
-
{
-
x = midd + 1;
-
}
-
}
-
else if (lent > lenp)
-
{
-
y = midd;
-
}
-
else
-
{
-
x = midd + 1;
-
}
-
}
-
}
-
return 0;
-
}
2011-03-26 16:23 发表于百度空间,今搬至CU。
阅读(1016) | 评论(0) | 转发(0) |