POJ 2109 :Power of Cryptography
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 18258 | Accepted: 9208 |
Description
to be only of theoretical interest.
This problem involves the efficient computation of integer roots of numbers.
Given an integer n>=1 and an integer p>= 1 you have to write a program that determines the n th positive root of p. In this problem, given such integers n and p, p will always be of the form k to the nth. power, for an integer k (this integer is
what your program must find).
Input
Output
Sample Input
2 16
3 27
7 4357186184021382204544
Sample Output
4
3
1234
这题有多坑。
。不想多说了。
。開始被那101次方被吓尿了。
。
还有坑爹的是我用G++提交就WA。
。
改C++就AC。。我真不知道怎么说才好。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath> using namespace std; int main()
{
double n, m;
while(scanf("%lf%lf", &n, &m)!=EOF)
{
printf("%.0lf\n", pow(m, 1/n));
} return 0;
}
注:这才是正常的吧。。。
#include<stdio.h>
#define N 1100
int n,a[N],k[10];
char p[N];
void pown()
{
int i,j,g,b[N];
for(i=1;i<N;i++)a[i]=0;
a[0]=1;
for(g=0;g<n;g++){
for(i=0;i<N;i++){
b[i]=a[i];
a[i]=0;
}
for(i=0;i<N;i++)
for(j=0;j<10;j++)
a[i+j]+=b[i]*k[j];
for(i=0;i<N-1;i++){
a[i+1]+=a[i]/10;
a[i]%=10;
}
}
}
int main()
{
int i,j,t;
while(~scanf("%d%s",&n,p)){
for(i=0;i<10;i++)k[i]=0;
for(t=0;p[t];t++)a[t]=p[t]-48;
for(j=t;t<N;t++)p[t]=0;
j--;
for(i=0,t=j;i<t,j>=0;i++,j--)p[j]=a[i];//倒置p
for(i=0;i<N;i++)a[i]=0;
for(i=9;i>=0;i--){// 从最高到个位依次确定
for(k[i]=9;k[i]>0;k[i]--){ //第i位上的值从9到0依次尝试
pown();//求k的n次方
for(j=N-1;j>0;j--)
if(a[j]!=p[j])break;
if(a[j]<=p[j])break;
//假设a(即此时的k^n值)小于等于p那么k的第i位值为当前值
}
}
for(i=9;i>0;i--)
if(k[i])break;
for(;i>=0;i--)printf("%d",k[i]);
puts("");
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
POJ 2109 :Power of Cryptography的更多相关文章
- POJ 1459:Power Network(最大流)
http://poj.org/problem?id=1459 题意:有np个发电站,nc个消费者,m条边,边有容量限制,发电站有产能上限,消费者有需求上限问最大流量. 思路:S和发电站相连,边权是产能 ...
- POJ 2406:Power Strings
Power Strings Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 41252 Accepted: 17152 D ...
- POJ 1459:Power Network 能源网络
Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 25414 Accepted: 13247 D ...
- Poj 2109 / OpenJudge 2109 Power of Cryptography
1.Link: http://poj.org/problem?id=2109 http://bailian.openjudge.cn/practice/2109/ 2.Content: Power o ...
- 贪心 POJ 2109 Power of Cryptography
题目地址:http://poj.org/problem?id=2109 /* 题意:k ^ n = p,求k 1. double + pow:因为double装得下p,k = pow (p, 1 / ...
- POJ 2109 -- Power of Cryptography
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 26622 Accepted: ...
- POJ 2109 Power of Cryptography 数学题 double和float精度和范围
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21354 Accepted: 107 ...
- poj 2109 Power of Cryptography
点击打开链接 Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16388 Ac ...
- POJ:2109-Power of Cryptography(关于double的误差)
Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Description Current work in cryptograp ...
随机推荐
- C#中禁止程序多开
原文:C#中禁止程序多开 方法一.使用Mutex bool createdNew; //返回是否赋予了使用线程的互斥体初始所属权 System.Threading.Mutex i ...
- Java程序猿从底层到CTO的技术路线图
首先.附一张图片展示所在各个阶段的工作职能: 其次.文字型描写叙述所在各个阶段的工作职能: Java程序猿 高级特性 反射.泛型.凝视符.自己主动装箱和拆箱.枚举类.可变參数.可变返回类型.增强循环. ...
- 发现SQL Server惊天大秘密!!
原文:发现SQL Server惊天大秘密!! --set statistics xml onCREATE TABLE T_TEST(ID INT IDENTITY PRIMARY KEY,Create ...
- c# 在cmd中用 7z解压缩文件
var exePath = @"C:\Program Files\7-Zip\7z.exe"; var path = @"I:\work\MusicCatcher2\Wi ...
- FastReport的再次使用
FastReport.Net是一款功能齐全的报表分析解决方案. 前两年工作的时候就是使用FastReport进行报表设计,只是当时使用的时候都是调用别人写好的帮助类,直接调用即可.当时让人觉得不明觉厉 ...
- UVa 353 - Pesky Palindromes
称号:字符串统计回文子的数量. 分析:dp,暴力.因为数据是小,直接暴力可以解决. 说明:(UVa最终评出800该). #include <iostream> #include <c ...
- 2014辽宁ACM省赛 Prime Factors
问题 L: Prime Factors 时间限制: 1 Sec 内存限制: 128 MB [提交][状态][论坛] 题目描写叙述 I'll give you a number , please te ...
- net开源cms系统
.net开源cms系统推荐 内容目录: 提起开源cms,大家第一想到的是php的cms,因为php开源的最早,也最为用户和站长们认可,随着各大cms系统的功能的不断完善和各式各样的开源cms的出现,. ...
- git-push(1) Manual Page
git-push(1) Manual Page NAME git-push - Update remote refs along with associated objects SYNOPSIS gi ...
- Python标准库简介
在<Python语言参考手册>描述中的描述Python语法和语义,而本手冊主要介绍了Python标准库的内容和使用,也介绍了一些发行库里可选的组件库. Python标准库包括的内容是非常广 ...