SGU111 Very simple problem(大数开方)
来源:互联网 发布:淘宝如何设置店铺首页 编辑:程序博客网 时间:2024/05/17 02:27
题意是,给出一个大整数(范围 10^1000),求2次方不大于该数的最大数
开始用的是C的高精度加上笔算开方,但是一整天都没出结果,我类个去啊……
无奈找了个 java 的代码,先出出气……
思想很简单,从1~10^500,区间二分求平方然后跟目标数比较。
第一次写(抄)java……
原题链接:http://acm.sgu.ru/problem.php?contest=0&problem=111
代码:
import java.io.*;import java.math.*;import java.util.*;public class Solution {public static void main(String[] args) {BigInteger r = new BigInteger("10");BigInteger l = new BigInteger("1");BigInteger one = new BigInteger("1");int tmp,cmp;BigInteger x,mid,ans;r = r.pow(500);Scanner cin = new Scanner(new BufferedInputStream(System.in));x = cin.nextBigInteger();ans = new BigInteger("-1");cmp = l.compareTo(r);while(cmp<=0){mid = (l.add(r)).shiftRight(1);tmp = (mid.pow(2)).compareTo(x);if(tmp<=0){ans=mid;l=mid.add(one);}else r=mid.subtract(one);cmp = l.compareTo(r);}System.out.println(ans);}}
- SGU111 Very simple problem(大数开方)
- sgu111:Very simple problem
- SGU111 Very simple problem
- SGU111 大数开方 Evolution
- sgu111 (大整数开方)
- POJ 2535 Very Simple Problem(水~)
- 1166 Very Simple Problem
- [Java]Very simple problem
- 111. Very simple problem
- SGU111 高精度开方
- sgu111高精度开方
- FOJ 1350 Very Simple Problem
- FZU 1350 Very Simple Problem
- POJ 2535 Very Simple Problem
- SGU 111 Very simple problem
- [SGU]111. Very simple problem
- SGU 111 Very simple problem
- poj 2535 Very Simple Problem
- C#用SQL语句操作ACCESS
- android listview与sqlite数据绑定
- PHP编程乱码问题整理
- 如何快速提高写代码的水平?
- 位平面介绍
- SGU111 Very simple problem(大数开方)
- 深入HTML5: HTML5 本地存储( Local Storage )的前世今生
- 系统性能监控--linux top命令详解
- Java【多线程知识总结(10)】线程通信之wait()与notify()的运用--模拟指挥官指挥2个连队交替轰炸战区<另外的写法>
- HDU OJ 题目分类
- c#操作Access[下]
- some+script
- flex FaultEvent捕获java异常
- HTTP消息