解方程 题解
解方程
https://ac.nowcoder.com/acm/contest/5600/G
二分求解
因为Math.log用成了Math.log10而wa了10发。
注意一下当精度特别高的时候就跳出循环 否则会tle
import java.util.*; import java.math.*; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.PrintWriter; public class Main { public static HashMap<Integer,Long>map = new HashMap<>(); public static void main(String args[])throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); in.nextToken(); int a = (int)in.nval; in.nextToken(); int b = (int)in.nval; in.nextToken(); int c = (int)in.nval; double l=0,r=1000000009,mid=(l+r)/2.0; while(l<=r) { mid=(l+r)/2.0; if(r-l<=0.00000001) { out.print(String.format("%.7f",l)); break; } if(Math.pow(mid,a)+b*Math.log(mid)==c) { out.print(String.format("%.7f",mid)); break; } else if(Math.pow(mid,a)+b*Math.log(mid)<c) l = mid; else if(Math.pow(mid,a)+b*Math.log(mid)>c) r = mid; } out.flush(); } }