推荐

新开了个公众号

欢迎扫码订阅

Advertisements

pb中操作剪切板

今天一整个下午的结果

win32 api 定义

Function ulong GlobalAlloc(ulong uFlags, ulong dwBytes) library “Kernel32.dll” ;
Function ulong GlobalLock(ulong lm) library “Kernel32.dll” ;
Function boolean GlobalUnlock(ulong lm) library “Kernel32.dll” ;
Function ulong CopyMemory(ulong des, String src, ulong length) library “Kernel32.dll” ALIAS FOR “RtlMoveMemory”

function boolean OpenClipboard(ulong _null ) Library “user32.dll”
function boolean EmptyClipboard() Library “user32.dll”
function ulong RegisterClipboardFormatA(ref String format) Library “user32.dll”
function ulong GetClipboardData( ulong winhandle) Library “user32.dll”
function ulong SetClipboardData( ulong winhandle,ulong lp_d) Library “user32.dll”
function boolean CloseClipboard() Library “user32.dll”

将数据保存到剪切板的函数

public subroutine tormrclip (string msg);
boolean lb_1
String ls_f
ls_f = msg +char(0)
lb_1 =this.openclipboard(0)
if lb_1 = false then return
if this.EmptyClipboard() = false then return
ulong lm,lv,lf
lm =this.GlobalAlloc(2,len(ls_f) + 1 )
if lm = 0 then return
lv = this.GlobalLock(lm)
if lv = 0 then return
this.copymemory(lv,ls_f,len(ls_f) + 1 )
this.GlobalUnlock(lm)
this.SetClipboardData(50269,lm)
this.CloseClipboard()
end subroutine

动态规划-装载问题

问题

c=[16,18]
w=[2,5,13,8,4]

设计要点

求第一艘船的最大装载

解设:m[i,j]为当船剩余容量为j时,装载i,i+1,…n的最大值。
也就是:第一艘船的最大装载量=m[1,16]的值(当船的容量为16时,装载[2,5,13,8,4]的最大值)。
要计算f[i,j]的值,再设:第i个集装箱得重量为<span class="MathJax_SVG" id="MathJax-Element-1-Frame" tabindex="0" data-mathml="wi” role=”presentation” style=”font-size: 100%; display: inline-block; position: relative;”>wi,m[i+1,j],m[i+1,j-<span class="MathJax_SVG" id="MathJax-Element-2-Frame" tabindex="0" data-mathml="wi” role=”presentation” style=”font-size: 100%; display: inline-block; position: relative;”>wi]
当 j>=0 && j<<span class="MathJax_SVG" id="MathJax-Element-3-Frame" tabindex="0" data-mathml="wi” role=”presentation” style=”font-size: 100%; display: inline-block; position: relative;”>wi时,m[i,j]=m[i+1,j],因为这种情况下无法装载第i个集装箱,所以与m[i+1,j]的值相同
当j>=<span class="MathJax_SVG" id="MathJax-Element-4-Frame" tabindex="0" data-mathml="wi” role=”presentation” style=”font-size: 100%; display: inline-block; position: relative;”>wi时,f[i,j]=max(f[i+1,j],f[i+1,j-<span class="MathJax_SVG" id="MathJax-Element-5-Frame" tabindex="0" data-mathml="wi” role=”presentation” style=”font-size: 100%; display: inline-block; position: relative;”>wi] + <span class="MathJax_SVG" id="MathJax-Element-6-Frame" tabindex="0" data-mathml="wi” role=”presentation” style=”font-size: 100%; display: inline-block; position: relative;”>wi),f[i+1,j-<span class="MathJax_SVG" id="MathJax-Element-7-Frame" tabindex="0" data-mathml="wi” role=”presentation” style=”font-size: 100%; display: inline-block; position: relative;”>wi] + <span class="MathJax_SVG" id="MathJax-Element-8-Frame" tabindex="0" data-mathml="wi” role=”presentation” style=”font-size: 100%; display: inline-block; position: relative;”>wi表示装载第i个集装箱

<span class="MathJax_SVG" id="MathJax-Element-9-Frame" tabindex="0" data-mathml="f[i,j]={f[i,j]=f[i+1,j]0⩽j&lt;wif[i,j]=max(f[i+1,j],f[i+1,j−wi]+wi)j⩾wi” role=”presentation” style=”font-size: 100%; display: inline-block; position: relative;”>f[i,j]={f[i,j]=f[i+1,j]0⩽j<wif[i,j]=max(f[i+1,j],f[i+1,j−wi]+wi)j⩾wi

这个问题的边界就是:f[n,0]-f[n,wi-1]=0,f[n,wi]-f[n,c1]=wi

构造最优解,也就是如何确定第一艘船装载的内容

<span class="MathJax_SVG" id="MathJax-Element-10-Frame" tabindex="0" data-mathml="∵” role=”presentation” style=”font-size: 100%; display: inline-block; position: relative;”>f[1,16]= max(f[2,16],f[2,14] + 2)
<span class="MathJax_SVG" id="MathJax-Element-11-Frame" tabindex="0" data-mathml="∴” role=”presentation” style=”font-size: 100%; display: inline-block; position: relative;”>if f[1,16] > f[2,16] 则装载第1个集装箱 else 不装载

pb窗口自适应

1。新建一个窗口。

为窗口写一个函数f_resize()大部分工作就在这里。
无输入参数
返回值为整形:

environment env
integer ii_ScreenWidth,ii_ScreenHeight
double WRadio,HRadio,Radio
integer ii_WinBolderWidth,ii_WinBolderHeight
getenvironment(env)
ii_WinBolderWidth=this.width - this.WorkSpaceWidth()//取得窗体的边框宽度
ii_WinBolderHeight=this.height - this.WorkSpaceHeight()
ii_ScreenWidth=env.screenwidth
ii_ScreenHeight=env.screenheight
//compute the radio that need be resize

WRadio=ii_ScreenWidth/800 //标准认为屏幕分辨率为800*600
HRadio=ii_ScreenHeight/600//计算出屏幕相对800*600分辨率的变化量
Radio=Min(WRadio,HRadio)
if Radio=1.0 then //if the screen is default 800*600
return 0
end if
this.hide()
this.width=(this.width - ii_WinBolderWidth)*Radio + ii_WinBolderWidth
this.height=(this.height - ii_WinBolderHeight)*Radio + ii_WinBolderHeight
integer i
dragobject temp//用于取各种控件

for i=1 to upperbound(this.control)
temp=this.control[i]//调整大小,位置
temp.width=temp.width*Radio
temp.x=temp.x*Radio
temp.y=temp.y*Radio
temp.Height=temp.Height*Radio
choose case typeof(temp)
case tab!
tab mtab
mtab=temp
mtab.textsize = mtab.textsize*Radio//设置字体
case commandbutton!
commandbutton cb
cb = temp
cb.textsize = cb.textsize*Radio

case singlelineedit!
singlelineedit sle
sle = temp
sle.textsize=sle.textsize*Radio
case editmask!
editmask em
em = temp
em.textsize = em.textsize*Radio

case statictext!
statictext st
st = temp
st.textsize = st.textsize*Radio

case datawindow! // datawindows get zoomed
datawindow dw
dw = temp
dw.Object.DataWindow.zoom = string(int(Radio*100))//注意DATAWINDOW与其它控件的不同

case picturebutton!
picturebutton pb
pb = temp
pb.textsize = pb.textsize*Radio

case checkbox!
checkbox cbx
cbx = temp
cbx.textsize = cbx.textsize*Radio

case dropdownlistbox!
dropdownlistbox ddlb
ddlb = temp
ddlb.textsize = ddlb.textsize*Radio

case groupbox!
groupbox gb
gb = temp
gb.textsize = gb.textsize*Radio

case listbox!
listbox lb
lb = temp
lb.textsize = lb.textsize*Radio

case multilineedit!
multilineedit mle
mle = temp
mle.textsize = mle.textsize*Radio

case radiobutton!
radiobutton rb
rb = temp
rb.textsize = rb.textsize*Radio

end choose
next
this.show()
return 0