m.ru
(: 1 . : 16 : 27%)
X , Y , Z .
, , W .
: INPUT.TXT X, Y, Z W (1 ≤ X, Y, Z ≤ 100, 1 ≤ W ≤ 1000).
: OUTPUT.TXT .
INPUT.TXT | OUTPUT.TXT | |
10 25 15 40 |
Time limit 10- !
Program Podarki_deda_Moroza;
var x,y,z,w,i,j,t,k:integer;
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
readln(x,y,z,w);
k:=0;
for i:=0 to w div x do
for j:=0 to w div y do
for t:=0 to w div z do
if x*i+y*j+z*t=w then inc(k);
write(k);
close(input);
close(output);
end.
Accepted!
Program Podarki_deda_Moroza;
var x,y,z,w,i,j,t,k:integer;
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
readln(x,y,z,w);
k:=0;
for i:=0 to w div x do
for j:=0 to (w-x*i) div y do
for t:=0 to (w-x*i-y*j) div z do
if x*i+y*j+z*t=w then inc(k);
write(k);
close(input);
close(output);
end.
Program Podarki_deda_Moroza;
var x,y,z,w,i,j,t,k:integer;
begin
readln(x,y,z,w);
k:=0;
for i:=0 to w div x do
for j:=0 to (w-x*i) div y do
if (w-x*i-y*j) mod z=0 then
inc(k);
write(k);
end.
: | g.in |
: | g.out |
: | 2 |
: | 64 |
A 1, A 2,, AM. , . N. , , .
N (1£ N £109), M (1£ M £15) M A 1, A 2,, AM (1£ Ai £109).
K , , . K , . , , . , .
, 0. , , 1 ( ).
g.in | g.out |
5 2 1 2 | 2 2 1 |
7 2 1 2 | -1 |
5 2 3 4 |
|
|
Accepted!
var s:int64;
n,i,j,k,m,min:longint;
b:array[1..15] of longint;
a,c:array[0..15] of byte;
flag:byte;
begin
assign (input,'input.txt');
reset (input);
assign (output,'output.txt');
rewrite (output);
|
s:=0;
for i:=1 to m do
begin
read(b[i]);
s:=s+2*b[i];
end;
if s<n then
begin
|
close (input);
close (output);
halt;
end;
|
if s=n then
begin
writeln(2*m);
for i:=1 to m do
write(b[i],' ',b[i],' ');
close (input);
close (output);
halt;
end;
for i:=0 to m do a[i]:=0;
flag:=0;
min:=maxlongint;
while a[0]=0 do
begin
s:=0; k:=0;
for j:=1 to m do
begin
k:=k+a[j];
s:=s+a[j]*b[j];
|
if s=n then flag:=1;
|
if (s=n) and (k<min) then
min:=k;
for j:=1 to m do c[j]:=a[j];
end;
i:=m;
while a[i]=2 do
begin
dec(i);
end;
inc(a[i]);
end;
if flag=0 then
begin
|
close (input);
close (output);
halt;
end;
writeln(min);
|
for j:=1 to m do
begin
if c[j]=1 then write (b[j],' ');
if c[j]=2 then write (b[j],' ',b[j],' ');
end;
close (input);
close (output);
end.
: lantern.in
: lantern.out
: 1
: 256
- M - , . . , N , , .., , i (1 ≤ i ≤ N) [ ai, bi ], 0 ≤ ai < bi ≤ M.
, .
.
|
|
.
: M , N (1 ≤ M ≤ 106, 1 ≤ N ≤ 105). N ai bi.
.
, .
lantern.in | lantern.out |
8 2 1 5 4 8 | 7 1 |
8 2 0 6 6 8 | 8 0 |
program fonari;
var al,ap:array[1..100000] of longint;
i,j,li,l,p,n,m,k:longint;
procedure quicksort(m,t:longint);
var i,j,w,w1,x:longint;
begin
i:=m; j:=t; x:=al[(m+t) div 2];
repeat
while al[i]<x do inc(i);
while al[j]>x do dec(j);
if i<=j then
begin
w:=al[i]; al[i]:=al[j]; al[j]:=w;
w1:=ap[i]; ap[i]:=ap[j]; ap[j]:=w1;
inc(i); dec(j);
end;
until i>j;
if m<j then quicksort(m,j);
if i<t then quicksort(i,t);
end;
begin
assign(input,'lantern.in');
assign(output,'lantern.out');
reset(input);
rewrite(output);
{ }
readln(m,n);
for i:=1 to n do
readln(al[i],ap[i]);
{ al ap}
quicksort(1,n);
{ }
l:=al[1]; p:=ap[1]; li:=ap[1]-al[1];
if al[1]<>0 then k:=1
else k:=0;
for i:=2 to n do
begin
if ((al[i]>=l)and(al[i]<=p)) and (ap[i]>p)
then
begin
li:=li+(ap[i]-p);
p:=ap[i];
end;
if al[i]>p
then
begin
li:=li+(ap[i]-al[i]);
l:=al[i];
p:=ap[i];
inc(k);
end;
end;
if ap[n]<>m
then inc(k);
{ }
write(li,' ',k);
close(input);
close(output);
end.