<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Decode360's Blog

    業精于勤而荒于嬉 QQ:150355677 MSN:decode360@hotmail.com

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 ::  :: 管理 ::
      302 隨筆 :: 26 文章 :: 82 評論 :: 0 Trackbacks

    ??? 很早以前就想用PLSQL寫一個算24點的程序了,后來想了一下沒有研究下去,最近上ITPUB的時候正好大家都在討論,在大牛的基礎上修改了一下,基本上思想和算法都是沒有變的,就是學習了一下。還有兩個大問題沒有處理好,一是只用了枚舉法,用PLSQL應該可以換個更好的遞歸算法的;二是沒有濾重;反正最后的結果只是最簡單的得到答案而已。

    ?

    ??? 具體的可以參見:

    ??? http://www.itpub.net/viewthread.php?tid=1061129&extra=page%3D1%26amp%3Bfilter%3Ddigest&page=1

    ??? http://www.itpub.net/viewthread.php?tid=1077244&extra=&page=1

    ?

    ?

    ?

    create or replace function f_op (p_n1 number , p_op varchar2 , p_n2 number ) return number

    as

    begin

    ?? return case when p_op = '+' then p_n1 + p_n2

    ?????????????? when p_op = '-' then p_n1 - p_n2

    ?????????????? when p_op = '*' then p_n1 * p_n2

    ?????????????? when p_op = '/' and p_n2<> 0 then p_n1 / p_n2

    ?????????????? else null

    ????????? end ;

    end f_op;

    /

    ?

    ?

    ?

    create or replace procedure pro_24(p1 number , p2 number , p3 number , p4 number ) as

    ?

    r_result number default 0 ;

    ?

    begin

    ?

    ? for r in (

    ????? with t_num as

    ????????? ( select 1 id ,p1 as n from dual

    ?????????? union

    ?????????? select 2 id ,p2 as n from dual

    ?????????? union

    ?????????? select 3 id ,p3 as n from dual

    ?????????? union

    ?????????? select 4 id ,p4 as n from dual),

    ?????????? t_op as

    ????????? ( select '+' as o from dual

    ?????????? union

    ?????????? select '-' as o from dual

    ?????????? union

    ?????????? select '*' as o from dual

    ?????????? union

    ?????????? select '/' as o from dual)

    ?????? select distinct

    ????????????? a.n? as a,

    ????????????? o1.o as o1,

    ????????????? b.n? as b,

    ????????????? o2.o as o2,

    ????????????? c.n? as c,

    ????????????? o3.o as o3,

    ????????????? d.n? as d

    ???????? from t_num a, t_num b, t_num c, t_num d,

    ????????????? t_op? o1, t_op? o2, t_op? o3

    ??????? where a.id not in (b.id, c.id, d.id)

    ????????? and b.id not in (c.id, d.id)

    ????????? and c.id <> d.id) loop

    ?

    ?????? r_result := f_op(f_op(f_op(r.a,r.o1,r.b),r.o2,r.c),r.o3,r.d);

    ?????? if r_result between 23.9 and 24.1 then

    ?????? dbms_output.put_line( '((' ||r.a||r.o1||r.b|| ')' ||r.o2||r.c|| ')' ||r.o3||r.d);

    ?????? end if ; --((a b) c) d

    ??????

    ?????? r_result := f_op(f_op(r.a,r.o1,f_op(r.b,r.o2,r.c)),r.o3,r.d);

    ?????? if r_result between 23.9 and 24.1 then

    ?????? dbms_output.put_line( '(' ||r.a||r.o1|| '(' ||r.b||r.o2||r.c|| '))' ||r.o3||r.d);

    ?????? end if ; --(a (b c)) d

    ??????

    ?????? r_result := f_op(f_op(r.a,r.o1,r.b),r.o2,f_op(r.c,r.o3,r.d));

    ?????? if r_result between 23.9 and 24.1 then

    ?????? dbms_output.put_line( '(' ||r.a||r.o1||r.b|| ')' ||r.o2|| '(' ||r.c||r.o3||r.d|| ')' );

    ?????? end if ; --(a b) (c d)

    ??????

    ?????? r_result := f_op(r.a,r.o1,f_op(f_op(r.b,r.o2,r.c),r.o3,r.d));

    ?????? if r_result between 23.9 and 24.1 then

    ?????? dbms_output.put_line(r.a||r.o1|| '((' ||r.b||r.o2||r.c|| ')' ||r.o3||r.d|| ')' );

    ?????? end if ; --a ((b c) d)

    ???????????

    ?????? r_result := f_op(r.a,r.o1,f_op(r.b,r.o2,f_op(r.c,r.o3,r.d)));

    ?????? if r_result between 23.9 and 24.1 then

    ?????? dbms_output.put_line(r.a||r.o1|| '(' ||r.b||r.o2|| '(' ||r.c||r.o3||r.d|| '))' );

    ?????? end if ; --a (b (c d))

    ??????????

    ? end loop ;

    ?

    end ;

    ?

    /

    ?

    ?

    exec pro_24( 3 , 3 , 8 , 8 );





    -The End-

    posted on 2008-12-28 23:55 decode360-3 閱讀(235) 評論(0)  編輯  收藏 所屬分類: SQL Dev
    主站蜘蛛池模板: 亚洲AV无码成H人在线观看| 成人免费福利视频| 免费一看一级毛片人| 国产亚洲精aa在线看| 亚欧在线精品免费观看一区| 亚洲成av人片天堂网| 日韩电影免费在线观看中文字幕| 亚洲AV无码乱码国产麻豆| 免费在线看黄的网站| 亚洲精品免费在线观看| 8x成人永久免费视频| 亚洲午夜一区二区电影院| 免费国产黄线在线观看| 亚洲精品乱码久久久久久V | 91福利免费体验区观看区| 亚洲午夜精品久久久久久人妖| 99re视频精品全部免费| 亚洲娇小性xxxx| 免费观看日本污污ww网站一区| 国产乱妇高清无乱码免费| 久久精品国产亚洲一区二区| 91香蕉国产线在线观看免费| 亚洲电影唐人社一区二区| 最近中文字幕mv免费高清电影| 福利片免费一区二区三区| 亚洲香蕉网久久综合影视| 亚洲精品视频在线免费| 亚洲熟妇AV乱码在线观看| 国产a v无码专区亚洲av| 99re免费视频| 亚洲av无码片vr一区二区三区 | 无码国产精品久久一区免费 | 亚洲成a人无码av波多野按摩| 成人国产精品免费视频| 亚洲国产成人精品青青草原| 波多野结衣免费视频观看| 国产精品免费观看调教网| 亚洲精品无AMM毛片| 久久亚洲精品视频| 四虎成人精品一区二区免费网站| 精品国产呦系列在线观看免费 |