Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.lang.Math;
- public class AntiQS {
- FastScanner in;
- PrintWriter out;
- public double binSearch(double a, int n) {
- double low = 0;
- double high = a;
- while (ans(a, high, n) - ans(a, low, n) > 0.001) {
- double m = (high - low) / 2;
- if (!touch(a, m, n)) {
- high = m;
- } else {
- low = m;
- }
- }
- return ans(a, high, n);
- }
- public double ans(double a, double b, int n) {
- boolean f = true;
- double[] E = new double[n];
- E[0] = a;
- E[1] = b;
- for (int i = 2; i < n; i++) {
- E[i] = ((E[i - 1] + 1) * 2) - E[i - 2];
- if (E[i] < 0) f = false;
- }
- return E[n - 1];
- }
- public boolean touch(double a, double b, int n) {
- boolean f = true;
- double[] E = new double[n];
- E[0] = a;
- E[1] = b;
- if (a <= 0 || b <= 0) {
- return false;
- }
- for (int i = 2; i < n; i++) {
- E[i] = ((E[i - 1] + 1) * 2) - E[i - 2];
- if (E[i] <= 0) f = false;
- }
- return f;
- }
- public void solve() throws IOException {
- int n;
- double a;
- a = Double.parseDouble(in.next());
- n = in.nextInt();
- double t = binSearch(a, n);
- out.print(t);
- }
- public void run() {
- try {
- in = new FastScanner(new File("style.in"));
- out = new PrintWriter(new File("style.out"));
- solve();
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- class FastScanner {
- BufferedReader br;
- StringTokenizer st;
- FastScanner(File f) {
- try {
- br = new BufferedReader(new FileReader(f));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- String next() {
- while (st == null || !st.hasMoreTokens()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
- int nextInt() {
- return Integer.parseInt(next());
- }
- }
- public static void main(String[] arg) {
- new AntiQS().run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement