Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does 3 compare the size of two continued fractions in java

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how 3 in java compares the size of two consecutive scores. I hope you will gain something after reading this article. Let's discuss it together.

(1) the continuous fraction ratio can be expressed as (a _ 0 ~ a _ 1 ~ A _ 2, … , an), such an intuitive mathematical expression is as follows: enter n, followed by a number, which represents a0mena1, respectively. , anm, followed by the number "m" 1, which means "b0", "b1", and "b0", respectively. Bn requires that the values of the above two continued fractions (marked as x and y, respectively) be compared, n and m not more than 100000, if the output x > y, the output ">", if x +-+-+ 4 1 2 3 3 4 1 2 3 3, the + above represents 1 line 0 represents 0 when the comparison is to the end of any array or after the size relationship has been compared, pass it back The result passed at this time is alternating in size, so, in the above example, the comparison to the last element is +, and then it begins to pass back (recursion in recursion). The size result when it finally reaches the position where the subscript is 0 is the final size result. : return: "" def helper (idx): # here is simply to compare the size of the corresponding subscript element if a [idx] > b [idx]: return 1 if a [idx]

< b[idx]: return -1 # 如果同时到达数组末尾,那么说明这两个连分数大小一样 if idx == n == m: return 0 # 如果a比较短,那么b后面剩下的元素都不用比了,在这一个下标判a[i] < b[i] if idx == n: return -1 # 反之亦然 if idx == m: return 1 # 如果在数组的开头没有比较出大小,那么就往后逐个比对 k = helper(idx + 1) # 当后面的比对得出结果之后,往回传递,这时候注意将大小对调 if k >

0: return-1 if k

< 0: return 1 return 0 # 在初始化变量的时候,*a可以作为一个列表变量 n, *a = list(map(int, input().split(' '))) m, *b = list(map(int, input().split(' '))) res = helper(0) print({0: '=', 1: '>

',-1:'

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report