强力推荐下载网址:http://www.crsky.com/soft/10457.html
翻阅地址:
http://book.idoican.com.cn/searchinfo/NewSearchServiceResult.aspx?publishType=-1&page=1&keyword=pascal%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1
(下载后翻阅).
varx,y:integer
begin
x:=(150-65*2)
div
(3-2)
y:=65-x
write(y,x)
end.
这好像是数学题的解法......
PASCAL的解法是用for语句:
var
x:integer
begin
for
x:=1
to
65
do
if
3*x+2*(65-x)=150
then
writeln(65-x,'and
',x)
end.
要显示所有的方案的话就不用想别的了,就是要你搜索,没什么好算法.怎么搜都一样了,dfs可能好写一点.
或许也有构造法吧?...让我想想
.-----
想不到了,搜吧.答案有6万多个,我把print注释掉了.
var ans:longint
state:array[1..6,1..6]of byte
num:array[1..6]of byte
function suc():boolean
var i:integer
begin
for i:=1 to 6 do
if(num[i]>4)then
exit(false)
exit(true)
end
procedure print()
var i,j:integer
begin
for i:=1 to 6 do begin
for j:=1 to 6 do
write(state[i,j])
writeln
end
end
procedure fill(dep:integer)
var i:integer
begin
for i:=1 to 6 do
state[dep,i]:=1
end
procedure search(dep:integer)
var i,j:longint
begin
if(dep>6)then begin
if(suc())then begin
//print()
inc(ans)
end
exit
end
fill(dep)
for i:=1 to 5 do begin
for j:=i+1 to 6 do begin
state[dep,i]:=0
state[dep,j]:=0
dec(num[i])
dec(num[j])
search(dep+1)
inc(num[i])
inc(num[j])
state[dep,i]:=1
state[dep,j]:=1
end
end
end
begin
fillchar(num,sizeof(num),6)
ans:=0
search(1)
writeln(ans)
end.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)