我的代码运行会超时(Time>1000ms),哪位能帮忙改成单循环的。。
-----偶是分割线----------
program test;
var X,A,B,c,d,e,f:longint;
begin
readln(X,A,B);
e:=0;f:=1;
for c:=1 to (X div A) do
For d:=1 to (X div B) do
begin
if (c*A+d*B)=X then e:=e+f;
end;
writeln(e);
end.
-----偶是分割线----------作者: 微点专家 时间: 2009-7-5 23:28 没法帮你了,兄弟。我数学打小就是最差的作者: qq2008444 时间: 2009-7-6 08:44 哈...算了..
只能自己想招了作者: qq2008444 时间: 2009-7-6 08:47 标题: 谷歌万岁...
比啥子有病和百度好用多了
改单循环后代码如下
-----偶是分割线----------
program test;
Var x,a,b,k,i:integer;
begin
Read(x,a,b);
k:=0;
For i:=1 to (x div a) do
if (x -i*a)mod b=0 then if x-i*a>=b then inc(k);
Writeln(k);
end.
-----偶是分割线----------作者: 微点专家 时间: 2009-7-6 09:21 其实也不一定,这几个搜索,都有自己的特色,有时候这个的结果让自己能满意,但是下一次又是另外一个让自己满意,我都轮换着使用的作者: qq2008444 时间: 2009-7-6 10:21 = =我当时写的8引擎搜索工具真好用作者: snhao 时间: 2009-7-6 11:02 标题: 人民币取法问题
有面值1元、2元、5元、10元的人民币,从中取出20张使其总值为80元,问有少种取法,并列出取法。
unit Unit1;
type
TForm1 = class(TForm)
Label1: TLabel;
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
idea:integer;
ione,itwo,ifive,iten:integer;
s:string;
begin
idea:=0;
For ione:=0 To 80 Do
For itwo:=0 To 40 Do
For ifive:=0 To 16 Do
For iten:=0 To 8 Do
if (ione+itwo*2+ifive*5+iten*10=80) then
begin
s:=' 壹元张数:'+inttostr(ione)+' 贰元张数:'+inttostr(itwo)
+' 伍元张数:'+inttostr(ifive)+' 拾元张数:'+inttostr(iten);
if (ione+itwo+ifive+iten)=20 then
begin
listbox1.Items.Add(s);
inc(idea);
end;
end;
label1.Caption:='取法有'+inttostr(idea)+'方法,具体如下:';
end;
我说。。。这是Pascal么 。。。这分明是Delphi。。。
这个题目和此题相似。。
---偶是分割线---
Description
用一张一元票换1分、2分和5分的硬币,每种至少一枚, 问有几种换法.
Input
无
Output
输出只有一行(这意味着末尾有一个回车符号),包括1个整数。
---偶是分割线---
Pascal代码
----偶是分割线----
program test;
var a,b,c,d:longint;
begin
d:=0;
for a:=1 to 93 do
for b:=1 to 47 do
for c:=1 to 19 do
if (a+2*b+5*c)=100 then d:=d+1;
writeln(d);
end.
----偶是分割线----