求算法 急急急~~~ 有数组A,A[0..99]有100个数(或者更多),想求出这样几对数,满足y1-y2在某个阈值内,x1-x2在某个阈值内,x1,x2表示第几个,y1,y2表示x1,x2对应的值,不知道用什么方法能快速实现,请各位大侠帮帮忙啊 在线等 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 y1,y2表示x1,x2对应的值什么意思 参考:http://apps.hi.baidu.com/share/detail/6227165 unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, DBGrids;type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Button1: TButton; Edit3: TEdit; Edit4: TEdit; StringGrid1: TStringGrid; procedure Search(IndexMin, IndexMax, ValueMin, ValueMax: Integer); procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private 愰尵 } public { Public 愰尵 } end;var Form1: TForm1;implementation{$R *.DFM}const A: Array[0..9] of Integer = (0,44,11,61,22,74,33,87,44,100);procedure TForm1.Search(IndexMin, IndexMax, ValueMin, ValueMax: Integer);var I: Integer; x1, x2: Integer; y1, y2: Integer;begin // 清空StringGrid1 for I := 1 to ( StringGrid1.RowCount - 1 ) do begin StringGrid1.Rows[I].Clear; StringGrid1.RowCount := 0; end; // 查找符合要求的组合 for x2 := 0 to ( IndexMax - IndexMin -1 ) do begin for x1 := ( x2 + 1 ) to ( IndexMax - IndexMin ) do begin // x1-x2的值在给定阈值内 if ( ( x1 - x2 ) >= IndexMin ) and ( ( x1 - x2) <= IndexMax ) then begin y1 := A[x1]; y2 := A[x2]; // y1-y2的值在给定的阈值内 if ( ( y1 - y2 ) >= ValueMin ) and ( ( y1 - y2 ) <= ValueMax ) then begin with StringGrid1 do begin RowCount := RowCount + 1; // 向StringGrid1中添加数据 Cells[0,RowCount-1] := IntToStr(x1); Cells[1,RowCount-1] := IntToStr(x2); Cells[2,RowCount-1] := IntToStr(y1); Cells[3,RowCount-1] := IntToStr(y2); end; end; end; end; end;end;procedure TForm1.Button1Click(Sender: TObject);var IndexMin, IndexMax: Integer; // x1-x2的最小值和最大值 ValueMin, ValueMax: Integer; // y1-y2的最小值和最大值begin IndexMin := StrToInt(Trim(Edit1.Text)); IndexMax := StrToInt(Trim(Edit2.Text)); ValueMin := StrToInt(Trim(Edit3.Text)); ValueMax := StrToInt(Trim(Edit4.Text)); Search(IndexMin, IndexMax, ValueMin, ValueMax);end;procedure TForm1.FormCreate(Sender: TObject);begin // 初始化StringGrid1 with StringGrid1 do begin ColCount := 4; RowCount := 0; StringGrid1.FixedCols := 2; FixedRows := 0; Cells[0,0] := 'x1'; Cells[1,0] := 'x2'; Cells[2,0] := 'y1'; Cells[3,0] := 'y2'; end;end;end. 学习学习先继续顶一下顶顶帖子高手们也请多多赐教http://topic.csdn.net/u/20110709/12/3ec63017-cef8-41e0-a524-c9b9dfe56d5c.htmlhttp://topic.csdn.net/u/20110611/12/3258c959-4f28-46b7-b5d6-46135d73036b.htmlhttp://topic.csdn.net/u/20110722/14/89f7440b-c4d7-4c9a-a4bb-a503f5135db2.htmlhttp://topic.csdn.net/u/20110729/10/a7bfaf06-0cf9-4580-8e91-d4e0b92066c6.htmlhttp://topic.csdn.net/u/20110811/16/e56e7cc1-d8c9-40af-92e3-c24ca103d17d.htmlhttp://topic.csdn.net/u/20110830/13/dfae4ca5-d2b9-4889-8a3c-6f7fb61936c9.htmlhttp://topic.csdn.net/u/20110831/17/427b6ab0-66c6-4f33-af26-ebd27b0dc541.htmlhttp://topic.csdn.net/u/20110901/09/83c2c668-cbe6-4db9-966d-bf2f47456811.htmlhttp://topic.csdn.net/u/20110905/12/a1161adb-8e5d-491a-b302-c9722edf2dab.htmlhttp://topic.csdn.net/u/20110906/10/86d49517-b7a6-4fae-982b-478d2d6e2a23.html 对于新手的一个难题,希望大家帮忙解决,悬赏100分 !! 如何在DBGRID(EH)中关联PopupMenu... ★★★升级散分啦★★★ 能否说一下判断文件是否存在的函数? 统计程序员年底红包多少,看看哪儿老板黑 如何得到视频采集卡上人视频信息! 请教,如何用delphi编写关闭其他应用程序的程序 关于打印报表的问题,请会的朋友回答一下。 D5下主程序和DLL如何共享1个DataBase连接别名 大侠,怎样保存在运行时设置的SOCKET的IP地址和PORT? delphi XE 已经可以试用下载! 标签打印,FastReport预览不能前后移动
什么意思
http://apps.hi.baidu.com/share/detail/6227165
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, DBGrids;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Edit3: TEdit;
Edit4: TEdit;
StringGrid1: TStringGrid;
procedure Search(IndexMin, IndexMax, ValueMin, ValueMax: Integer);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private 愰尵 }
public
{ Public 愰尵 }
end;var
Form1: TForm1;implementation{$R *.DFM}const
A: Array[0..9] of Integer = (0,44,11,61,22,74,33,87,44,100);procedure TForm1.Search(IndexMin, IndexMax, ValueMin, ValueMax: Integer);
var
I: Integer;
x1, x2: Integer;
y1, y2: Integer;
begin
// 清空StringGrid1
for I := 1 to ( StringGrid1.RowCount - 1 ) do
begin
StringGrid1.Rows[I].Clear;
StringGrid1.RowCount := 0;
end;
// 查找符合要求的组合
for x2 := 0 to ( IndexMax - IndexMin -1 ) do
begin
for x1 := ( x2 + 1 ) to ( IndexMax - IndexMin ) do
begin
// x1-x2的值在给定阈值内
if ( ( x1 - x2 ) >= IndexMin ) and ( ( x1 - x2) <= IndexMax ) then
begin
y1 := A[x1];
y2 := A[x2];
// y1-y2的值在给定的阈值内
if ( ( y1 - y2 ) >= ValueMin ) and ( ( y1 - y2 ) <= ValueMax ) then
begin
with StringGrid1 do
begin
RowCount := RowCount + 1;
// 向StringGrid1中添加数据
Cells[0,RowCount-1] := IntToStr(x1);
Cells[1,RowCount-1] := IntToStr(x2);
Cells[2,RowCount-1] := IntToStr(y1);
Cells[3,RowCount-1] := IntToStr(y2);
end;
end;
end;
end;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
IndexMin, IndexMax: Integer; // x1-x2的最小值和最大值
ValueMin, ValueMax: Integer; // y1-y2的最小值和最大值
begin
IndexMin := StrToInt(Trim(Edit1.Text));
IndexMax := StrToInt(Trim(Edit2.Text));
ValueMin := StrToInt(Trim(Edit3.Text));
ValueMax := StrToInt(Trim(Edit4.Text));
Search(IndexMin, IndexMax, ValueMin, ValueMax);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
// 初始化StringGrid1
with StringGrid1 do
begin
ColCount := 4;
RowCount := 0;
StringGrid1.FixedCols := 2;
FixedRows := 0;
Cells[0,0] := 'x1';
Cells[1,0] := 'x2';
Cells[2,0] := 'y1';
Cells[3,0] := 'y2';
end;
end;end.
继续顶一下
顶顶帖子高手们
也请多多赐教
http://topic.csdn.net/u/20110709/12/3ec63017-cef8-41e0-a524-c9b9dfe56d5c.html
http://topic.csdn.net/u/20110611/12/3258c959-4f28-46b7-b5d6-46135d73036b.html
http://topic.csdn.net/u/20110722/14/89f7440b-c4d7-4c9a-a4bb-a503f5135db2.html
http://topic.csdn.net/u/20110729/10/a7bfaf06-0cf9-4580-8e91-d4e0b92066c6.htmlhttp://topic.csdn.net/u/20110811/16/e56e7cc1-d8c9-40af-92e3-c24ca103d17d.html
http://topic.csdn.net/u/20110830/13/dfae4ca5-d2b9-4889-8a3c-6f7fb61936c9.html
http://topic.csdn.net/u/20110831/17/427b6ab0-66c6-4f33-af26-ebd27b0dc541.html
http://topic.csdn.net/u/20110901/09/83c2c668-cbe6-4db9-966d-bf2f47456811.html
http://topic.csdn.net/u/20110905/12/a1161adb-8e5d-491a-b302-c9722edf2dab.html
http://topic.csdn.net/u/20110906/10/86d49517-b7a6-4fae-982b-478d2d6e2a23.html