国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

算術編碼算法

2019-11-18 18:41:13
字體:
來源:轉載
供稿:網友
算術編碼算法
算術編碼是把一個信源表示為實軸上0和1之間的一個區(qū)間,信源集合中的每一個元素都用來縮短這個區(qū)間。
   算術編碼的過程如下:
(1)       設定編碼區(qū)間的高段為h,編碼區(qū)間的長度為g,EndC為編碼字符分配的高段,StartC
為字符分配區(qū)間的低端。
(2)       根據(jù)有限的信源估算出各元素的概率。
(3)       杜宇編碼的元素A1,根據(jù)(2)估算的概率和區(qū)間,計算出該元素編碼后的新的l,和h。其公式如下:
         h = StartC + g* K;
         l = Endc + g* K1;
其具體程序如下:           
             
const  Ca = 0.2;  Ce = 0.3;
      Ci = 0.2;  Co = 0.2;
      Cu = 0.1;
var
  Form1: TForm1;
   s: string;
   StartC, EndC: Extended;
implementation
{$R *.dfm}
PRocedure ConvertTo(s: string; var StartC, EndC: Extended);{將字符串變?yōu)閿?shù)值}
var n, i: integer;
    c: char;
    g: Extended;
begin
    StartC := 0;
    EndC := 1;
    n := Strlen(Pchar(s));
    for i := 1 to n do
    begin
       c := s[i];
       g := EndC - StartC;
       case C of
       'a':
         begin
            EndC :=StartC  + g * Ca;
            StartC := StartC + g * 0;
         end;
       'e':
          begin
            EndC := StartC + g * (Ca + Ce);
            StartC := StartC + g * Ca;
         end;
       'i':
          begin
            EndC := StartC + g * (Ca + Ce + Ci);
            StartC := StartC + g * (Ca + Ce);
         end;
       'o':
          begin
            EndC := StartC + g * (Ca + Ce + Ci + Co);
            StartC := StartC + g * (Ca + Ce + Ci);
         end;
       'u':
          begin
            EndC := StartC + g * (Ca + Ce + Ci + Co + Cu);
            StartC := StartC + g * (Ca + Ce + Ci + Co);
         end;
       else
           begin
            Showmessage(' 輸入的字符串有誤 ');
            exit;
           end;
      end;
    end;
end;
procedure NemuricalToStr(var s: String; var StartC, EndC: Extended);
{將數(shù)值轉換為字符串}
const eps = -1e-5;
begin
  if StartC-0.2 < -eps  then
    if (EndC- 0.2<= -eps) and (EndC > StartC) then
    begin
       StartC := StartC / 0.2;
       EndC := EndC / 0.2;
       s := s + 'a';
       if (StartC <>0) or (EndC <> 1) then
          NemuricaltoStr(s,StartC,EndC);
   end;
  if (StartC- 0.2 >= eps) and (StartC-0.5 < -eps) then
    if (EndC-0.5<= -eps) and (EndC>StartC) then
    begin
       StartC := StartC - 0.2;
       EndC := EndC - 0.2;
       StartC := StartC / 0.3;
       EndC := EndC / 0.3;
       s := s + 'e';
       if (StartC <>0) or (EndC <> 1) then
          NemuricaltoStr(s,StartC,EndC);
  end ;
  if (StartC- 0.5>= eps) and (StartC- 0.7< -eps) then
    if (EndC-0.7<= -eps) and (EndC>StartC) then
    begin
       StartC := StartC - 0.5;
       EndC := EndC - 0.5;
       StartC := StartC / 0.2;
       EndC := EndC / 0.2;
       s := s + 'i';
       if (StartC <>0) or (EndC <> 1) then
          NemuricaltoStr(s,StartC,EndC);
  end ;
  if (StartC-0.7 >= eps) and (StartC-0.9 < -eps) then
    if (EndC-0.9<=-eps) and (EndC>StartC) then
    begin
       StartC := StartC - 0.7;
       EndC := EndC - 0.7;
       StartC := StartC / 0.2;
       EndC := EndC / 0.2;
       s := s + 'o';
       if (StartC <>0) or (EndC <> 1) then
          NemuricaltoStr(s,StartC,EndC);
  end ;
  if (StartC -0.9>=eps) and (StartC-1 < -eps) then
    if (EndC-1<= -eps) and (EndC>StartC) then
    begin
       StartC := StartC - 0.9;
       EndC := EndC - 0.9;
       StartC := StartC / 0.1;
       EndC := EndC / 0.1;
       s := s + 'u';
       if (StartC <>0) or (EndC <> 1) then
          NemuricaltoStr(s,StartC,EndC);
    end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
   s := Edit1.Text;
   ConvertTo(s,StartC,EndC);
   Edit2.Text := FloattoStr(StartC);
   Edit3.Text := FloattoStr(EndC);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
    s := '';
    StartC := StrToFloat(Edit2.Text);
    EndC := StrtoFloat(Edit3.Text);
    NemuricalToStr(s,StartC,Endc);
    Edit1.Text := s;
end;
end.

上一篇:TreeView使用筆記

下一篇:關于在COM中使用可選參數(shù)的研究

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
學習交流
熱門圖片

新聞熱點

疑難解答

圖片精選

網友關注

主站蜘蛛池模板: 长治市| 玛沁县| 弥勒县| 新建县| 赫章县| 尼勒克县| 开封县| 广昌县| 三亚市| 绩溪县| 眉山市| 金塔县| 手游| 平阳县| 舞钢市| 晋宁县| 陇川县| 潮州市| 肥东县| 伊春市| 南通市| 股票| 盐亭县| 乳山市| 广西| 江陵县| 宽城| 海安县| 宁国市| 晋江市| 昌江| 柞水县| 扎赉特旗| 视频| 河西区| 山阳县| 江达县| 白沙| 洪洞县| 固始县| 安国市|