1 / 3

10077 : The Stern-Brocot Number System

10077 : The Stern-Brocot Number System. ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10077 : The Stern-Brocot Number System 解題者: 陳柏均 解題日期: 20 11 年 3 月 4 日

yvonne
Télécharger la présentation

10077 : The Stern-Brocot Number System

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 10077: The Stern-Brocot Number System • ★★☆☆☆ • 題組:Problem Set Archive with Online Judge • 題號:10077: The Stern-Brocot Number System • 解題者:陳柏均 • 解題日期:2011年3月4日 • 題意:給予初值( , ),將分子與分子相加、分母語分母相加,求出一個新的序列( ,, ),利用這個方式建立一個樹狀圖(下圖),題目將輸入兩個正整數分別代表分子與分母,找出 到這個分數的路徑,印出R或L。當輸入為1、1時結束離開離開。

  2. 題意範例: INPUT:5 78783231 1 OUTPUT: LRRLRRLRRLRLLLLRLRRR • 解法:類似binarytree的解法,將輸入的值丟進function做 recursive,因為求出來的數大小必介於原本的兩數之間,所以就一個個進行比較直到找出這個數為止。

  3. 解法範例: ※void lway(double lson,double lmon,double x,double y,double rson,double rmon); ※void rway(double lson,double lmon,double x,double y,double rson,double rmon); • 討論: 分母等於零時將分數設為2147483647

More Related