StringGrid3.RowCount:=SpinEdit2.Value+1;
StringGrid3.DefaultColWidth:=round((StringGrid3.Width-10)/StringGrid3.ColCount);
StringGrid3.DefaultRowHeight:=round((StringGrid3.Height-10)/StringGrid3.RowCount);
for i:=1 to SpinEdit1.Value do
StringGrid3.Cells[i,0]:='Ï'+inttostr(i);
for i:=1 to SpinEdit2.Value do
StringGrid3.Cells[0,i]:='A'+inttostr(i);
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
if a[i-1]<strtoint(StringGrid1.Cells[i,j]) then a[i-1]:=strtoint(StringGrid1.Cells[i,j]);
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
StringGrid3.Cells[i,j]:=inttostr(a[i-1]-strtoint(StringGrid1.Cells[i,j]));
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var i,j:integer;
begin
Form1.Height:=480;
for i:=1 to SpinEdit1.Value do begin
for j:=1 to SpinEdit2.Value do begin
StringGrid1.Cells[i,j]:='';
StringGrid3.Cells[i,j]:='';
end;
StringGrid2.Cells[i,0]:='';
Form2.StringGrid1.Cells[i,1]:='';
Form2.StringGrid2.Cells[i,1]:='';
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Form2.Close;
end;
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
begin
if not (key in ['0'..'9',#8]) then key:=#0;
end;
end;
procedure TForm1.StringGrid2KeyPress(Sender: TObject; var Key: Char);
begin
begin
if not (key in ['0'..'9','.',',',#8]) then key:=#0;
end;
end;
procedure TForm1.StringGrid3KeyPress(Sender: TObject; var Key: Char);
begin
begin
if not (key in ['0'..'9',#8]) then key:=#0;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
i,j,max,maxr:integer;
f:boolean;
a: array [0..12] of Real;
begin
f:=true;
max:=0;
maxr:=0;
for i:=0 to SpinEdit2.Value-1 do
a[i]:=0;
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
if StringGrid1.Cells[i,j]='' then f:=false;
if f=false then ShowMessage('Çíà÷åíèÿ íå îïðåäåëåíû')
else begin
f:=true;
// ÊÐÈÒÅÐÈÉ ÁÀÉÅÑÀ
if CheckBox1.Checked=true then begin
for i:=1 to SpinEdit1.Value do
if StringGrid2.Cells[i,0]='' then f:=false;
if f=false then ShowMessage('Çíà÷åíèÿ íå îïðåäåëåíû')
else begin
// äëÿ ìàòðèöû èãðû ïîäñò÷åò ìàò îæèäàíèÿ
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
a[j-1]:=a[j-1]+strtoint(StringGrid1.Cells[i,j])*strtofloat(StringGrid2.Cells[i,0]);
// äëÿ ìàòðèöû èãðû îïðåäåëåíèÿ ìàêñèìóìà
if RadioButton3.Checked=true then begin
for i:=1 to SpinEdit2.Value-1 do
if a[max]<a[i] then max:=i;
if Form1.Height<757 then
ShowMessage('Íàøåë îïòèìàëüíûé ìàêñèìóì: À'+inttostr(max+1)); end;
// äëÿ ìàòðèöû ðèñêîâ îïðåäåëåíèÿ ìèíèìóìà
if RadioButton4.Checked=true then begin
for i:=1 to SpinEdit2.Value-1 do
if a[max]>a[i] then max:=i; ShowMessage('Íàøåë îïòèìàëüíûé ìèíèìóì: À'+inttostr(max+1)); end;
// äëÿ ðàñ÷èòàííîé ìàòðèöû ðèñêîâ
if (Form1.Height=757) and (RadioButton3.Checked=true) then begin
f:=true;
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
if StringGrid3.Cells[i,j]='' then f:=false;
if f=false then ShowMessage('Çíà÷åíèÿ íå îïðåäåëåíû')
else begin
for i:=0 to SpinEdit2.Value-1 do
a[i]:=0;
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
a[j-1]:=a[j-1]+strtoint(StringGrid3.Cells[i,j])*strtofloat(StringGrid2.Cells[i,0]);
for i:=1 to SpinEdit2.Value-1 do
if a[maxr]>a[i] then maxr:=i;
if max=maxr then ShowMessage('Îïòèìàëüíûå çíà÷åíèÿ ñîâïàäàþò: À'+inttostr(max+1))
else ShowMessage('Íàøåë îïòèìàëüíûé ìàêñèìóì: À'+inttostr(max+1)+'; Íàøåë îïòèìàëüíûé ìèíèìóì: À'+inttostr(maxr+1))
end;
end;
end;
end;
// ÊÐÈÒÅÐÈÉ ËÀÏËÀÑÀ
If (CheckBox2.Checked=true) and (RadioButton1.Checked=true) then begin
// äëÿ ìàòðèöû èãðû ïîäñò÷åò ìàò îæèäàíèÿ
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
a[j-1]:=a[j-1]+strtoint(StringGrid1.Cells[i,j]);
// äëÿ ìàòðèöû èãðû îïðåäåëåíèÿ ìàêñèìóìà
if RadioButton3.Checked=true then Begin
for i:=1 to SpinEdit2.Value-1 do
if a[max]<a[i] then max:=i;
if Form1.Height<757 then
ShowMessage('Íàøåë îïòèìàëüíûé ìàêñèìóì: À'+inttostr(max+1)); end;
// äëÿ ìàòðèöû ðèñêîâ îïðåäåëåíèÿ ìèíèìóìà
if RadioButton4.Checked=true then begin
for i:=1 to SpinEdit2.Value-1 do
if a[max]>a[i] then max:=i; ShowMessage('Íàøåë îïòèìàëüíûé ìèíèìóì: À'+inttostr(max+1)); end;
// äëÿ ðàñ÷èòàííîé ìàòðèöû ðèñêîâ
if (Form1.Height=757) and (RadioButton3.Checked=true) then begin
f:=true;
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
if StringGrid3.Cells[i,j]='' then f:=false;
if f=false then ShowMessage('Çíà÷åíèÿ íå îïðåäåëåíû')
else begin
for i:=0 to SpinEdit2.Value-1 do
a[i]:=0;
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
a[j-1]:=a[j-1]+strtoint(StringGrid3.Cells[i,j]);
for i:=1 to SpinEdit2.Value-1 do
if a[maxr]>a[i] then maxr:=i;
if max=maxr then ShowMessage('Îïòèìàëüíûå çíà÷åíèÿ ñîâïàäàþò: À'+inttostr(max+1))
else ShowMessage('Íàøåë îïòèìàëüíûé ìàêñèìóì: À'+inttostr(max+1)+'; Íàøåë îïòèìàëüíûé ìèíèìóì: À'+inttostr(maxr+1))
end;
end;
end;
f:=true;
// ÒÐÅÒÈÉ ÊÐÈÒÅÐÈÉ
If (CheckBox2.Checked=true) and (RadioButton2.Checked=true) then begin
for i:=1 to SpinEdit1.Value do
if StringGrid2.Cells[i,0]='' then f:=false;
if f=false then ShowMessage('Çíà÷åíèÿ íå îïðåäåëåíû')
else begin
// äëÿ ìàòðèöû èãðû ïîäñò÷åò ìàò îæèäàíèÿ
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
a[j-1]:=a[j-1]+strtoint(StringGrid1.Cells[i,j])*strtofloat(StringGrid2.Cells[i,0]);
// äëÿ ìàòðèöû èãðû îïðåäåëåíèÿ ìàêñèìóìà
if RadioButton3.Checked=true then begin
for i:=1 to SpinEdit2.Value-1 do
if a[max]<a[i] then max:=i;
if Form1.Height<757 then
ShowMessage('Íàøåë îïòèìàëüíûé ìàêñèìóì: À'+inttostr(max+1)); end;
// äëÿ ìàòðèöû ðèñêîâ îïðåäåëåíèÿ ìèíèìóìà
if RadioButton4.Checked=true then begin
for i:=1 to SpinEdit2.Value-1 do
if a[max]>a[i] then max:=i; ShowMessage('Íàøåë îïòèìàëüíûé ìèíèìóì: À'+inttostr(max+1)); end;
// äëÿ ðàñ÷èòàííîé ìàòðèöû ðèñêîâ
if (Form1.Height=757) and (RadioButton3.Checked=true) then begin
f:=true;
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
if StringGrid3.Cells[i,j]='' then f:=false;
if f=false then ShowMessage('Çíà÷åíèÿ íå îïðåäåëåíû')
else begin
for i:=0 to SpinEdit2.Value-1 do
a[i]:=0;
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
a[j-1]:=a[j-1]+strtoint(StringGrid3.Cells[i,j])*strtofloat(StringGrid2.Cells[i,0]);
for i:=1 to SpinEdit2.Value-1 do
if a[maxr]>a[i] then maxr:=i;
if max=maxr then ShowMessage('Îïòèìàëüíûå çíà÷åíèÿ ñîâïàäàþò: À'+inttostr(max+1))
else ShowMessage('Íàøåë îïòèìàëüíûé ìàêñèìóì: À'+inttostr(max+1)+'; Íàøåë îïòèìàëüíûé ìèíèìóì: À'+inttostr(maxr+1))
end;
end;
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s: string;
i,j,l,p,k:integer;
f:boolean;
a: array [0..13] of integer;
begin
f:=true;
for i:=1 to SpinEdit1.Value do
for j:=1 to SpinEdit2.Value do
if StringGrid1.Cells[i,j]='' then f:=false;
if f=false then ShowMessage('Çíà÷åíèÿ íå îïðåäåëåíû')
else begin
p:=0; k:=0;
for i:=1 to SpinEdit1.Value do
a[i]:=0;
if RadioButton3.Checked=true then
for l:=1 to SpinEdit2.Value-1 do
for j:=l+1 to SpinEdit2.Value do begin
for i:=1 to SpinEdit1.Value do begin
if strtoint(StringGrid1.Cells[i,l])>=strtoint(StringGrid1.Cells[i,j]) then p:=p+1;
if strtoint(StringGrid1.Cells[i,1])<strtoint(StringGrid1.Cells[i,j]) then k:=k+1; end;
if (p=SpinEdit1.Value) then a[j]:=-1;
if (k=SpinEdit1.Value) then a[l]:=-1;
p:=0;
k:=0;
end;
if RadioButton4.Checked=true then
for l:=1 to SpinEdit2.Value-1 do
for j:=l+1 to SpinEdit2.Value do begin
for i:=1 to SpinEdit1.Value do begin
if strtoint(StringGrid1.Cells[i,l])<=strtoint(StringGrid1.Cells[i,j]) then p:=p+1;
if strtoint(StringGrid1.Cells[i,1])>strtoint(StringGrid1.Cells[i,j]) then k:=k+1; end;
if (p=SpinEdit1.Value) then a[j]:=-1;
if (k=SpinEdit1.Value) then a[l]:=-1;
p:=0;
k:=0;
end;
for j:=1 to SpinEdit2.Value do
if a[j]=-1 then begin
s := s + 'A' + inttostr(j)+' ';
if SpinEdit2.Value>2 then
for i:=1 to SpinEdit1.Value do
StringGrid1.Cells[i,j]:=StringGrid1.Cells[i,j+1];
SpinEdit2.Value:=SpinEdit2.Value-1; end;
if s='' then ShowMessage('Íå òðåáóåòñÿ') else begin
ShowMessage('Óáðàë '+s);
If SpinEdit2.Value<=2 then
for i:=1 to SpinEdit2.Value do
if (a[i]=0) then ShowMessage(' ðåçóëüòàòå óïðîùåíèÿ îñòàëàñü òîëüêî 1 ñòðàòåãèÿ, ñëåäóò ñ÷èòàòü îïòèìàëüíîé À'+inttostr(i))
end;
end;
end;
end.
Дополнительный модуль:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, Spin;
type
TForm2 = class(TForm)
StringGrid1: TStringGrid;
Label1: TLabel;
SpinEdit1: TSpinEdit;
Button1: TButton;
StringGrid2: TStringGrid;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure SpinEdit1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses unit1;
{$R *.dfm}
procedure TForm2.FormCreate(Sender: TObject);
var i:integer;
begin
Form2.Top:=320;
Form2.Left:=520;
SpinEdit1.Value:=Form1.SpinEdit1.Value;
StringGrid1.ColCount:=SpinEdit1.Value;