SGU111 大数开方 Evolution
2014-01-04 22:11
218 查看
Problem: You are given natural number X. Find such maximum integer number that it square is not greater than X.(X.length<1000)
解法:想用java水过但是跪了。上网查到了笔算开方,不过另一段短小的程序却更神奇。完全不会= 。= 于是收录在这里了。
Solution: A small piece of code can solve it but I don't know why. _(:3」∠)_
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int l;
int work(int o,char *O,int I) {
char c, *D=O ;
if (o>0) {
for (l=0;D[l];D[l++]-=10) {
D[l++] -= 120;
D[l] -= 110;
while (!work(0,O,l)) D[l] += 20;
putchar((D[l]+1032)/20);
}
putchar(10);
}
else {
c = o+(D[I]+82)%10-(I>l/2)*(D[I-l+I]+72)/10-9;
D[I] += I<0?0:!(o=work(c/10,O,I-1))*((c+999)%10-(D[I]+92)%10);
}
return o;
}
int main() {
char s[1200];
s[0]='0';
scanf("%s",s+1);
if (strlen(s)%2 == 1) work(2,s+1,0);
else work(2,s,0);
return 0;
}
解法:想用java水过但是跪了。上网查到了笔算开方,不过另一段短小的程序却更神奇。完全不会= 。= 于是收录在这里了。
Solution: A small piece of code can solve it but I don't know why. _(:3」∠)_
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int l;
int work(int o,char *O,int I) {
char c, *D=O ;
if (o>0) {
for (l=0;D[l];D[l++]-=10) {
D[l++] -= 120;
D[l] -= 110;
while (!work(0,O,l)) D[l] += 20;
putchar((D[l]+1032)/20);
}
putchar(10);
}
else {
c = o+(D[I]+82)%10-(I>l/2)*(D[I-l+I]+72)/10-9;
D[I] += I<0?0:!(o=work(c/10,O,I-1))*((c+999)%10-(D[I]+92)%10);
}
return o;
}
int main() {
char s[1200];
s[0]='0';
scanf("%s",s+1);
if (strlen(s)%2 == 1) work(2,s+1,0);
else work(2,s,0);
return 0;
}
相关文章推荐
- Very simple problem - SGU 111(大数开方)
- SGU111 Very simple problem(大数开方)
- sgu-111-111. Very simple problem(java大数)
- SGU 111 大数开根号
- sgu111高精度开方
- sgu111-112大数运算
- sgu111 (大整数开方)
- UVa 10023 - Square root 大数开方
- JAVA BigInteger 类用例 1:求一个大整数的平方根的整数部分 (SGU 111)
- 牛顿法和拟牛顿法,大数开方
- SGU111 Very simple problem
- SGU 299 Triangle(大数)
- 大数开方
- UVa 10023 - Square root 大数开方
- SGU 111 Very simple problem 翻译 题解
- 快速切题 sgu 112. a^b-b^a 大数 次方 难度:0 非java:1
- sgu 154 二分 + 数学方法 sgu 111 二分 + 高精度 (Java)
- Java大数模板——加法、减法、乘法、除法、开方、求余
- SGU 111 Very simple problem
- sgu-112(java 大数)