ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1021. Таинство суммы

It's my AC solution.
Послано NoFate 12 янв 2003 21:04
Sorry/Re: It's my AC solution.
Послано NoFate 12 янв 2003 21:04
> program f;
const max_n=50000;
type list=array[1..max_n]of integer;
     nn=0..max_n;

var n1,n2,i:nn;
    first,second:list;

function isfind(qq:longint):boolean;
var j,count:nn;
    temp:boolean;
begin
   count:=1; temp:=false;
   while (second[count]>=qq) and (not temp) do
        if second[count]=qq then
          temp:=true
        else
          inc(count);
   isfind:=temp;
end;

procedure out_yes;
begin
   writeln('YES');
   halt;
end;

begin
   readln(n1);
   for i:=1 to n1 do
      readln(first[i]);
   readln(n2);
   for i:=1 to n2 do
      readln(second[i]);
   for i:=1 to n1 do
      if isfind(10000-first[i]) then out_yes;
   writeln('NO');
end.
SOme Notice-useful 4 all
Послано Locomotive 13 янв 2003 14:12
Hi Dear;
Here is my recommends for your program, as it is all right, but i
have some idea for you,
if you want...
i will be glad if you tell me such as notices about my solutions in
webboard!
anyway:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const max_n=50000;
type list=array[1..max_n]of integer;
     nn=0..max_n;

var n1,n2,i:nn;
{1-it was better to use 'Word' type instead of nn... it is more
formal}
    first,second:list;

function isfind(qq:longint):boolean;
var j,count:nn;
{j never used in program. it is useless memory}
    temp:boolean;
{2-you can don`t use temp and exit procedure when you find answer
such:}
begin
   count:=1; temp:=false;
   while (second[count]>=qq) and (not temp) do
        if second[count]=qq then
   {2-1-begin}
          temp:=true
{2-2-and here use just
          isfind:=true;}
    {2-3- exit}
  {2-4- end}
        else
          inc(count);
   isfind:=temp;
{2-5- and the previous line is not need}
end;

procedure out_yes;
begin
   writeln('YES');
   halt;
end;

begin
   readln(n1);
   for i:=1 to n1 do
      readln(first[i]);
   readln(n2);
   for i:=1 to n2 do
      readln(second[i]);
   for i:=1 to n1 do
      if isfind(10000-first[i]) then out_yes;
{i think 'halt' in algorithmics proglems is not so beauty! as you see
in this section books
 so you can use one boolean integer to see is somethink does in
output already or not,
 and also if you change your searching list and source list you
doesn`t need to read all of second
 list datas. i.e. ---->
            readln(n2);
            for i:=1 to n2 do
               readln(second[i]);
            readln(n1);
            for i:=1 to n1 do
            begin
               readln(first[i]);
               if isfind(10000-first[i]) then out_yes;
            end;
         writeln('NO');
      end.
 so as you see if it has an answer(i mean 'YES') then it doesn`t need
to read more from
 second list(in your prog. first is second and second is first!).
}
~~~~~~~~~~~~~~~~~~~~~~~
i have so more idea.
if you use a sorting and then use binary search then it will increase
your prog. speed
and also after sort you can use something like merge (in merge sort) :
repeat
  inc(first_pointer)
until first_list[first_pointer]+second_list[pointer]>=10000;

ans so more...

~~~~~~~~~~~~~~~~~~~~~~~~
i wish these recommends be useful for you in next programs
with best wish for you
Aidin Nassiri/17/From Iran