Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Потрепаться";
Текущий архив: 2003.11.17;
Скачать: [xml.tar.bz2];

Вниз

Нужна здоровая критика!   Найти похожие ветки 

 
Nelud   (2003-10-23 12:35) [0]

Доброго времени суток уважаемые Мастера!
Решил выложить на Ваш суд исходники некоторых решенных мной задач.

Задача 1
One curious child has a set of N little bricks (5 <= N <= 500). From these bricks he builds different staircases. Staircase consists of steps of different sizes in a strictly descending order. It is not allowed for staircase to have steps equal sizes. Every staircase consists of at least two steps and each step contains at least one brick
Your task is to write a program that reads from input file one number N and writes to output file the only number Q — amount of different staircases that can be built from exactly N bricks.
Задача 2
You are given a number 1<=N<=50. Every ticket has its 2N-digit number. We call a ticket lucky, if the sum of its first N digits is equal to the sum of its last N digits. You are also given the sum of ALL digits in the number. Your task is to count an amount of lucky numbers, having the specified sum of ALL digits.
Задача 3
You have to find the sum of two numbers with maximal size of 1.000.000 digits.
The first line of an input file contains a single number N (1<=N<=1000000) the length of the integers (in order to make their lengths equal, some leading zeroes can be added). It is followed by these integers written in columns. That is, the next N lines contain two digits each, divided by a space. Each of the two given integers is not less than 1, and the length of their sum does not exceed N.
Задача 4
In the problem you are to determine the minimal diameter that may compensate unexactness of projectile hit in each concrete case. Assume that all the targets are convex polygons. A hit is the situation when the circle crater that the projectile leaves (the crater diameter equals to the one of the projectile) covers if only one point of the target.
Sample Input
2 -1 8
0 1
1 0
2 0
3 1
3 2
2 3
1 3
0 2
Sample Output
2.000


 
Nelud   (2003-10-23 12:35) [1]

Решение задачи 1:
{$A+,B-,D+,E+,F-,G-,I+,L+,N+,O-,P-,Q-,R-,S+,T-,V+,X+}
{$M 16384,0,655360}

program staircases;

Var m : array [0..500] of extended;
i,n,step,k:longint;
Ans,buff : extended;

Begin
readln(N);
for i:=3 to 500 do
m[i]:=(i-1) div 2;
Ans:=0;
step:=2;
while m[n]>0 do
begin
Ans:=Ans+m[N];
Step:=step+1;
for i:=500 downto 3 do
begin
buff:=0;
K:=i;
while K>=step do
begin
K:=k-step;
buff:=buff+m[k]
end;
m[i]:=buff;
end;
end;
writeln(Ans:20:0);
end.

Рекурсивное решение

program staircases;

Type Ar=array [1..50,1..50] of longint;

Function T(N,i:longint;Var p:ar):longint;
Var Ans,k:longint;
Begin
if i=2 then
if p[n,i]>0 then Ans:=p[n,i] else
begin
Ans:=(n-1) div 2;
p[n,i]:=Ans;
end
else begin
K:=N;
Ans:=0;
While K>=i do begin
K:=k-i;
if p[k,i-1]>0 then Ans:=Ans+p[k,i-1] else
begin
p[k,i-1]:=T(k,i-1,p);
Ans:=ans+p[k,i-1];
end;
end;
end;
T:=Ans;
end;

Var N,I,Ans:longint;
p:ar;

Begin
readln(N);
i:=2;
while T(N,i,p)>0 do begin
Ans:=ans+T(N,i,p);
i:=i+1;
end;
writeln(Ans);

end.

Работает медленно.


 
Nelud   (2003-10-23 12:36) [2]

Задача 2:
program lucky_tickets;

const Max=2000;

Var a:array [0..Max,1..100] of integer;
i,j,k,s,n,u,q:longint;
buf1,buf2:array [1..100] of longint;
ans : array [-100..100] of longint;

Begin
readln(n,s);
if odd(s) then begin writeln(0); halt(0); end;
s:=s div 2;
for i:=0 to 9 do
a[i,1]:=1;

u:=19;
for k:=2 to n do begin

for i:=u downto 1 do begin
q:=1;
while (q<=9) and (i-q>=0) do begin
for j:=1 to 100 do
a[i,j]:=a[i,j]+a[i-q,j];
q:=q+1;
end;
for j:=100 downto 1 do begin
if a[i,j]>9 then a[i,j+1]:=a[i,j+1]+a[i,j] div 10;
if a[i,j]>9 then a[i,j]:=a[i,j] mod 10;
end;
end;
u:=u+9;
if u>Max then u:=Max;
end;

{write(a[s,1]); write(a[s,2]); write(a[s,3]); write(a[s,4]);
writeln;}

for i:=1 to 100 do
buf1[i]:=a[s,101-i];
for i:=1 to 100 do
buf2[i]:=buf1[i];
for i:=100 downto 1 do
for j:=100 downto 1 do begin
ans[i+j-100]:=ans[i+j-100]+buf1[i]*buf2[j];
if ans[i+j-100]>9 then ans[i+j-101]:=ans[i+j-101]+ans[i+j-100] div 10;
if ans[i+j-100]>9 then ans[i+j-100]:=ans[i+j-100] mod 10;
end;
i:=-100;
while (ans[i]=0)and (i<=100) do
i:=i+1;
for J:=i to 99 do
write(ans[j]);
write(ans[100]);

end.


 
Nelud   (2003-10-23 12:36) [3]

Задача 3:

program superlongsum;

Var a,b,count,i,x,y,N,j,k : longint;

Begin
{assign(input,"input.txt");
assign(output,"output.txt");
reset(input);
rewrite(output);}
readln(N);
readln(x,y);
a:=x+y;
j:=1;
b:=0;
k:=0;
while J<=N do begin
x:=0;
y:=0;
if j<N then readln(x,y);
if k>=n then break;
j:=j+1;
b:=x+y;
if b<9 then
begin
k:=k+1;
write(a);
a:=b;
end;
if b>9 then
begin
k:=k+1;
write(a+1);
a:=b-10;
end;
if b=9 then
begin

while (b=9) and (j<N) do begin
j:=j+1;
count:=count+1;
readln(x,y);
b:=x+y;
end;
if j=n then count:=count+1;

if b<=9 then
begin
write(a);
for I:=1 to count do
write(9);
a:=b;
k:=k+count+1;
count:=0;
end
else
begin
write(a+1);
for i:=1 to count do
write(0);
a:=b-10;
k:=k+count+1;
count:=0;
end;
end;
end;

end.


 
Nelud   (2003-10-23 12:37) [4]

Задача 4:

{$A+,B-,D+,E+,F-,G-,I+,L+,N+,O-,P-,Q-,R-,S+,T-,V+,X+}
{$M 16384,0,655360}

program Shot_by_shell_on_target;

Function F(x1,x2,px,y1,y2,py:Longint):boolean;
Var A,B,C:Longint;
Begin
A:=sqr(x1-px)+sqr(y1-py);
B:=sqr(px-x2)+sqr(py-y2);
C:=sqr(x1-x2)+sqr(y1-y2);
F:=(a<=b+c) and (b<=a+c);
end;

Function GetH(x1,x2,xp,y1,y2,yp:longint):extended;

Function GetL(x1,y1,x2,y2:longint):extended;
Begin GetL:=sqrt( sqr(x1-x2) + sqr(y1-y2) ); end;

Var p,a,b,c:real;

Begin
A:=GetL(x1,y1,x2,y2);
B:=GetL(x2,y2,xp,yp);
C:=GetL(X1,y1,xp,yp);
p:=(A+B+C)/2;
if A=0 then GetH:=0 else
GetH:=(2*sqrt(p*(p-a)*(p-b)*(p-c)))/a;

end;

Function Crossing(x1,x2,y1,y2,x,y:longint):boolean;

Procedure GetEqation(x1,x2,y1,y2:longint;Var k,b:extended);
Begin
if x1-x2=0 then k:=2e10
else k:=(y1-y2)/(x1-x2);
b:=y1-k*x1;
end;

Var k,b,Ymin,Ymax:extended;

Begin
getEqation(x1,x2,y1,y2,k,b);
if k=0 then Crossing:=false
else begin
Ymin:=y1;
Ymax:=y2;
if y1>y2 then begin Ymin:=y2; Ymax:=y1; end;
Crossing:= ((y-b)/k>x) and (Ymin<y) and (Ymax>y);
end;
end;

Function Difside(y1,y2,y:longint):boolean;
Var min,max: longint;
Begin
min:=y1;
max:=y2;
if y1>y2 then begin min:=y2; max:=y1; end;
Difside:=(min<y) and (max>y);
end;

Function GetL(x1,y1,x2,y2:longint):real;
Begin GetL:=sqrt( sqr(x1-x2) + sqr(y1-y2) ); end;

Var p:array [0..110,1..2] of longint;
i,j,x,y,n,pp,p1,p2,count:longint;
l:extended;

Begin
read(x,y,n);
for i:=1 to n do
read(p[i,1],p[i,2]);
l:=2e10;

p[0,1]:=p[N,1];
p[0,2]:=p[n,2];
p[n+1,1]:=p[1,1];
p[n+1,2]:=p[1,2];
p[n+2,1]:=p[2,1];
p[n+2,2]:=p[2,2];

for i:=1 to N do
if L>getL(x,y,p[i,1],p[i,2]) then L:=getL(x,y,p[i,1],p[i,2]);
for i:=1 to N do
if f(p[i,1],p[i+1,1],x,p[i,2],p[i+1,2],y) then
if GetH(p[i,1],p[i+1,1],x,p[i,2],p[i+1,2],y)<L then l:=GetH(p[i,1],p[i+1,1],x,p[i,2],p[i+1,2],y);
L:=l*2;
count:=0;
For i:=1 to N-1 do
if crossing(p[i,1],p[i+1,1],p[i,2],p[i+1,2],x,y) then inc(count);
if crossing(p[n,1],p[1,1],p[n,2],p[1,2],x,y) then inc(count);

For i:=1 to N do
if (p[i,2]=y) and (p[i,1]>=x) and ( difside(p[i-1,2],p[i+1,2],y) ) then inc(count);

if count mod 2 <>0 then L:=0;
Writeln(L:20:3);
end.


 
Е-Моё имя   (2003-10-23 12:38) [5]

вторая с ошибкой


 
blackman   (2003-10-23 14:00) [6]

>Е-Моё имя
Ты прочитал не внимательно :)
В 17 ой


 
Nelud   (2003-10-23 17:44) [7]

А как вам стиль кода и.т.д?


 
Blackman   (2003-10-23 18:37) [8]

Длинно!
p[0,1]:=p[N,1];
p[0,2]:=p[n,2];
p[n+1,1]:=p[1,1];
p[n+1,2]:=p[1,2];
p[n+2,1]:=p[2,1];
p[n+2,2]:=p[2,2];
А это просто недопустимо в приличном обществе.


 
Е-Моё имя   (2003-10-23 18:39) [9]


> [6] blackman © (23.10.03 14:00)

и правда )))


 
Nelud   (2003-10-24 17:52) [10]

O.K. тогда
1. Писать короче.
2. ... ??? ....



Страницы: 1 вся ветка

Форум: "Потрепаться";
Текущий архив: 2003.11.17;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.48 MB
Время: 0.011 c
1-56564
Oleg_
2003-11-06 13:18
2003.11.17
Как определить ширину Canvas.TextOut


1-56745
TRyaSS
2003-11-06 14:44
2003.11.17
Что такое системная переменная Path?


7-56925
TALLA
2003-07-16 00:18
2003.11.17
С завершением сервиса беда:(


1-56707
Quit
2003-11-07 10:49
2003.11.17
Поиск формы


1-56612
mc_duck
2003-11-07 17:25
2003.11.17
чтение компонента из файла





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский