java大数总结 -尊龙游戏旗舰厅官网
hdu1753
话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫“大明”。
这时他已经不是那个只会做100以内加法的那个“小明”了,现在他甚至会任意长度的正小数的加法。
现在,给你两个正的小数a和b,你的任务是代表大明计算出a b的值。
input
本题目包含多组测试数据,请处理到文件结束。
每一组测试数据在一行里面包含两个长度不大于400的正小数a和b。
output
请在一行里面输出输出a b的值,请输出最简形式。详细要求请见sample output。
sample input
1.1 2.9 1.1111111111 2.3444323343 1 1.1sample output
4 3.4555434454 2.1 import java.util.*; import java.math.*; public class main {static int maxn=105;static int mod=(int)(1e9 7);public static void main(string[] args) {scanner cin=new scanner(system.in);int ca=0;while(cin.hasnext()) {ca ;bigdecimal a=cin.nextbigdecimal();bigdecimal b=cin.nextbigdecimal();system.out.println(a.add(b).striptrailingzeros().toplainstring());//先去掉末尾的后导0,然后转化为字符串}cin.close();} }51nod1030
给出一个36进制的大数(0-9,a-z),将其转为10进制并输出。
input
输入:36进制的大数,每一位用0-9,a-z来表示,a表示10,z表示35。(a的长度 <= 100000)
output
输出:该数的10进制表示
sample input
1azsample output
1691 import java.math.*; import java.util.*; public class main { //num需要转换的数字,from原数的进制,to要转换的进制private static string change(string num,int from,int to) {return new java.math.biginteger(num,from).tostring(to);}public static void main (string[] args) {scanner cin = new scanner(system.in);while(cin.hasnext()) {string num=cin.next();system.out.println(change(num,36,10));}cin.close();}}超时代码
import java.math.*;import java.util.*; public class main {void solve () {scanner cin = new scanner(system.in);int maxn=(int)(1e5 6); //int t=cin.nextint();int ca=0;while(cin.hasnext()) {ca ; string num=cin.next();biginteger ans=biginteger.zero;int len=num.length();int k=num.length()-1;for(int i=0;i51nod 1166
给出一个大整数n,求不大于n的平方根的最大整数。例如:n = 8,2 * 2 < 8,3 * 3 > 8,所以输出2。
input
给出一个大数n(n的长度 <= 100000)。
output
输出不大于sqrt(n)的最大整数。
sample input
9sample output
3 from math import * from decimal import * getcontext().prec=10**5 print(floor(decimal((input())).sqrt())) import java.math.*; import java.util.*; public class main {//牛顿迭代法void solve () {scanner cin = new scanner(system.in);while(cin.hasnext()) {string s=cin.next();int len=s.length();if(len<9) {system.out.println((long)math.sqrt(double.valueof(s)));continue;}biginteger num=new biginteger(s);if(len%2==0) {s=s.substring(0, len/2 1);}else {s=s.substring(0,(len 1)/2);}biginteger x=new biginteger(s);if(s.equals("1"))system.out.println("1");else {while(num.compareto(x.multiply(x))<0) {x=x.add(num.divide(x)).divide(new biginteger("2"));}}system.out.println(x);}cin.close();}//num需要转换的数字,from原数的进制,to要转换的进制private static string change(string num,int from,int to) {return new java.math.biginteger(num,from).tostring(to);}public static void main (string[] args) {main work = new main();work.solve ();} }hdu1865
you will be given a string which only contains ‘1’; you can merge two adjacent ‘1’ to be ‘2’, or leave the ‘1’ there. surly, you may get many different results. for example, given 1111 , you can get 1111, 121, 112,211,22. now, your work is to find the total number of result you can get.
input
the first line is a number n refers to the number of test cases. then n lines follows, each line has a string made up of ‘1’ . the maximum length of the sequence is 200.
output
the output contain n lines, each line output the number of result you can get .
sample input
3 1 11 11111sample output
1 2 8 import java.math.*; import java.util.*; public class main {void solve () {scanner cin = new scanner(system.in);int maxn=207;biginteger[] f=new biginteger[maxn];f[1]=biginteger.valueof(1);f[2]=biginteger.valueof(2);for(int i=3;i总结
- 上一篇: java中map集合类的用法(hashm
- 下一篇: