<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 閱讀(229) 評論(0)  編輯  收藏 所屬分類: SQL Dev
    主站蜘蛛池模板: 亚洲黄色片免费看| 中文亚洲AV片不卡在线观看| 亚洲成网777777国产精品| 亚洲大尺码专区影院| 日本人成在线视频免费播放| 国产成人高清精品免费鸭子| 亚洲国产精品美女| 国产婷婷高清在线观看免费| 国产午夜不卡AV免费| 国产亚洲情侣一区二区无| 污污免费在线观看| 成人片黄网站色大片免费| 亚洲日产2021三区| 四虎永久免费观看| 国产一区二区三区亚洲综合| 午夜无遮挡羞羞漫画免费| 亚洲精品无码99在线观看| yy一级毛片免费视频| 亚洲日韩在线观看| 国内精品99亚洲免费高清| 亚洲成AV人片天堂网无码| 久久嫩草影院免费看夜色| 国产精品亚洲A∨天堂不卡| 免费毛片a线观看| 亚洲另类激情综合偷自拍| 日韩精品人妻系列无码专区免费| 亚洲中文字幕不卡无码| 在线精品免费视频| 最近免费视频中文字幕大全| 亚洲综合中文字幕无线码| 最近2019中文免费字幕| 免费一级毛片无毒不卡| 一级毛片人与动免费观看| 亚洲精品伊人久久久久| 亚洲国语精品自产拍在线观看 | 日韩精品免费一级视频| 亚洲国产美女视频| 亚洲国产无套无码av电影| 免费一级成人毛片| 国产免费无码一区二区| 成人午夜免费视频|