Guest User

P2

a guest
Dec 8th, 2019
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package summerp1;
  7.  
  8.  
  9. import java.util.*;
  10. import java.io.*;
  11.  
  12. public class four {
  13.  
  14. static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  15. static StringTokenizer st;
  16. static int N,M;
  17. static long n[],m[];
  18. static String temp;
  19. public static void main(String[] args)throws IOException {
  20. N = readInt();
  21. n = new long [N+2];
  22. for(int i = 1; i <= N+1; i++)n[i] = readLong();
  23. M = readInt();
  24. m = new long [M+2];
  25. for(int i = 1; i <= M+1; i++)m[i] = readLong();
  26. if(N < M){
  27. long t[] = n;
  28. n = m;
  29. m = t;
  30. }
  31. double mid = 0, m = 0;
  32. double difference = Integer.MAX_VALUE;
  33. int a = readInt(), b = readInt();
  34. for(int i = a; i <= b; i++){
  35. //System.out.println(Math.abs(f(i)-g(i))+" "+f(i)+" "+g(i)+" "+i);
  36. if(Math.abs(f(i)-g(i)) < difference){
  37. mid = i;
  38. difference = Math.abs(f(i)-g(i));
  39. //System.out.println(difference+" "+i);
  40. }
  41. }
  42. temp = Integer.toString((int)mid);
  43. String key = "";
  44. difference = Integer.MAX_VALUE;
  45. for(int i = 0; i < 10; i++){
  46. String temp2 = temp+"."+Integer.toString(i);
  47. double temp3 = Double.parseDouble(temp2);
  48. if(Math.abs(f(temp3)-g(temp3)) < difference){
  49. key = Integer.toString(i);
  50. difference = Math.abs(f(temp3)-g(temp3));
  51. }
  52. }
  53. temp = temp + "." + key;
  54.  
  55. key = "";
  56. difference = Integer.MAX_VALUE;
  57. for(int i = 0; i < 10; i++){
  58. String temp2 = temp+Integer.toString(i);
  59. double temp3 = Double.parseDouble(temp2);
  60. if(Math.abs(f(temp3)-g(temp3)) < difference){
  61. key = Integer.toString(i);
  62. difference = Math.abs(f(temp3)-g(temp3));
  63. }
  64. }
  65. temp += key;
  66.  
  67. key = "";
  68. difference = Integer.MAX_VALUE;
  69. for(int i = 0; i < 10; i++){
  70. String temp2 = temp+Integer.toString(i);
  71. double temp3 = Double.parseDouble(temp2);
  72. if(Math.abs(f(temp3)-g(temp3)) < difference){
  73. key = Integer.toString(i);
  74. difference = Math.abs(f(temp3)-g(temp3));
  75. }
  76. }
  77. temp += key;
  78.  
  79. key = "";
  80. difference = Integer.MAX_VALUE;
  81. for(int i = 0; i < 10; i++){
  82. String temp2 = temp+Integer.toString(i);
  83. double temp3 = Double.parseDouble(temp2);
  84. if(Math.abs(f(temp3)-g(temp3)) < difference){
  85. key = Integer.toString(i);
  86. difference = Math.abs(f(temp3)-g(temp3));
  87. }
  88. }
  89. temp += key;
  90.  
  91. key = "";
  92. difference = Integer.MAX_VALUE;
  93. for(int i = 0; i < 10; i++){
  94. String temp2 = temp+Integer.toString(i);
  95. double temp3 = Double.parseDouble(temp2);
  96. if(Math.abs(f(temp3)-g(temp3)) < difference){
  97. key = Integer.toString(i);
  98. difference = Math.abs(f(temp3)-g(temp3));
  99. }
  100. }
  101. temp += key;
  102.  
  103. key = "";
  104. difference = Integer.MAX_VALUE;
  105. for(int i = 0; i < 10; i++){
  106. String temp2 = temp+Integer.toString(i);
  107. double temp3 = Double.parseDouble(temp2);
  108. if(Math.abs(f(temp3)-g(temp3)) < difference){
  109. key = Integer.toString(i);
  110. difference = Math.abs(f(temp3)-g(temp3));
  111. }
  112. }
  113. temp += key;
  114.  
  115. key = "";
  116. difference = Integer.MAX_VALUE;
  117. for(int i = 0; i < 10; i++){
  118. String temp2 = temp+Integer.toString(i);
  119. double temp3 = Double.parseDouble(temp2);
  120. if(Math.abs(f(temp3)-g(temp3)) < difference){
  121. key = Integer.toString(i);
  122. difference = Math.abs(f(temp3)-g(temp3));
  123. }
  124. }
  125. temp += key;
  126.  
  127. key = "";
  128. difference = Integer.MAX_VALUE;
  129. for(int i = 0; i < 10; i++){
  130. String temp2 = temp+Integer.toString(i);
  131. double temp3 = Double.parseDouble(temp2);
  132. if(Math.abs(f(temp3)-g(temp3)) < difference){
  133. key = Integer.toString(i);
  134. difference = Math.abs(f(temp3)-g(temp3));
  135. }
  136. }
  137. temp += key;
  138.  
  139. System.out.println(temp);
  140. //System.out.println(f(Double.parseDouble(temp))+" "+g(Double.parseDouble(temp)));
  141. }
  142. static double f(double mid){
  143. double f = 0;
  144. for(int i = 1; i <= N+1; i++){
  145. if(i == N+1){f += n[i]; break;}
  146. f += (double)Math.pow(mid, N-i+1) * n[i];
  147. }
  148. return f;
  149. }
  150. static double g(double mid){
  151. double g = 0;
  152. for(int i = 1; i <= M+1; i++){
  153. if(i == M+1){g += m[i]; break;}
  154. g += (double)Math.pow(mid, M-i+1) * m[i];
  155. }
  156. return g;
  157. }
  158. static int check(double mid){
  159. double f = 0, s = 0;
  160. for(int i = 1; i <= N+1; i++){
  161. if(i == N){f += n[i]; break;}
  162. f += (double)Math.pow(mid, N-i) * n[i];
  163. }
  164. for(int i = 1; i <= M+1; i++){
  165. if(i == M){f += m[i]; break;}
  166. s += (double)Math.pow(mid, M-i) * m[i];
  167. }
  168. if(f > s){
  169. return 1;
  170. }
  171. else return 2;
  172. }
  173. static String next () throws IOException {
  174. while (st == null || !st.hasMoreTokens())
  175. st = new StringTokenizer(br.readLine().trim());
  176. return st.nextToken();
  177. }
  178. static long readLong () throws IOException {
  179. return Long.parseLong(next());
  180. }
  181. static int readInt () throws IOException {
  182. return Integer.parseInt(next());
  183. }
  184. static double readDouble () throws IOException {
  185. return Double.parseDouble(next());
  186. }
  187. static String readLine () throws IOException {
  188. return br.readLine().trim();
  189. }
  190.  
  191. }
RAW Paste Data