const nx = 20; var x: array[1..nx, 1..nx] of integer;z:array[1..nx*2] of integer; i, j, k,n,r,t: integer; begin Writeln('Введите размер матрицы n');Read(n); for i := 1 to n do begin for j := 1 to n do begin Read(k);x[i, j] := k; end;end; Writeln('Исходный массив'); for i := 1 to n do begin for j := 1 to n do begin Write(x[i, j]:4); if x[i, j]>0 then begin t:=t+1; z[t]:=x[i, j];end; end; Writeln; end; Writeln;Writeln('Одномерный массив'); for j := 1 to t do Write(z[j]:4); end.
#include <iostream>
typedef long long ll;
using namespace std;
bool ll_is_valid(ll t, ll N, ll x, ll y)
{
return t / x + (t - x) / y >= N;
}
ll f(ll N, ll x, ll y)
{
ll R = 1;
while (!ll_is_valid(R,N,x,y)) R *= 2;
ll L = R / 2;
while(R - L > 1)
{
ll M = (L + R) / 2;
if (!ll_is_valid(M,N,x,y)) {L = M;}
else {R = M;}
}
return R;
}
int main()
{
ll N,x,y;
cin >> N >> x >> y;
if(x > y) swap( x, y );
cout << f(N, x, y) << std::endl;
}
var x: array[1..nx, 1..nx] of integer;z:array[1..nx*2] of integer;
i, j, k,n,r,t: integer;
begin
Writeln('Введите размер матрицы n');Read(n);
for i := 1 to n do begin
for j := 1 to n do begin
Read(k);x[i, j] := k; end;end;
Writeln('Исходный массив');
for i := 1 to n do begin
for j := 1 to n do begin
Write(x[i, j]:4);
if x[i, j]>0 then begin t:=t+1; z[t]:=x[i, j];end;
end;
Writeln; end;
Writeln;Writeln('Одномерный массив');
for j := 1 to t do
Write(z[j]:4);
end.