<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 :: 首頁 :: 新隨筆 :: 聯系 ::  :: 管理 ::
      397 隨筆 :: 33 文章 :: 29 評論 :: 0 Trackbacks
    PLSQL算24點
    ?
    ?
    ??? 很早以前就想用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);
    ?
    posted on 2008-12-28 23:55 decode360 閱讀(159) 評論(0)  編輯  收藏 所屬分類: 06.PLSQL
    主站蜘蛛池模板: 无码人妻一区二区三区免费看 | 在线观看亚洲免费视频| 91在线亚洲精品专区| 国产精品偷伦视频观看免费| 亚洲熟妇无码另类久久久| 成人免费夜片在线观看| 亚洲男人在线无码视频| 成年女人A毛片免费视频| 国产精品亚洲lv粉色| 日韩在线免费电影| 国产亚洲视频在线观看网址| 凹凸精品视频分类国产品免费| 国产亚洲一卡2卡3卡4卡新区| 免费a在线观看播放| v片免费在线观看| 亚洲无线码在线一区观看| 久久这里只精品国产免费10 | 亚洲精品在线电影| 日韩免费一区二区三区在线播放 | 婷婷综合缴情亚洲狠狠尤物| 黄页网站在线视频免费| 国产专区一va亚洲v天堂| 最新亚洲成av人免费看| 亚洲视频网站在线观看| 伊人久久五月丁香综合中文亚洲| 亚洲精品无码成人| 亚洲精品少妇30p| 国内成人精品亚洲日本语音| 男女一进一出抽搐免费视频| 国产亚洲无线码一区二区 | 久久久国产精品福利免费| 亚洲春色在线观看| 日本视频免费在线| 野花香在线视频免费观看大全| 亚洲国产精品久久人人爱| 国产一精品一aⅴ一免费| 久久国产精品成人免费| 亚洲区日韩精品中文字幕| 中文字幕亚洲日韩无线码| 桃子视频在线观看高清免费完整| 日本免费精品一区二区三区 |