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

Обсуждение задачи 1619. Big Brother

Please check my program. I got WA
Послано SoSimple 17 авг 2008 16:01
I don't know whats wrong with it

Program b;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  n,k,i,m:integer;
Begin
  readln(n);
  for i:=1 to n do
  begin
    readln(k,m);
    if k=m then
    begin
      writeln(1/(k+1):0:6);
    end
    else
      if m>k then writeln('0')
      else writeln(k/(k+m):0:6);
  end;



End.
Re: Please check my program. I got WA
Послано SabaRG 17 авг 2008 16:52
Why do you write :
if(k==m) return 1/(k+1)
?
if k=m=4, what do you return?

Edited by author 17.08.2008 16:52
Re: Please check my program. I got WA
Послано SoSimple 17 авг 2008 17:11
because if any moment the Bob's money is greater than this of Alex,Alex breaks all the windows.

0 0 0 0 -- Alex's good deeds

1 1 1 1 -- Bob's good deeds

if the  first time Bob do the good deed (or Mother gives the Bob first 1 euro),at this time Alex breaks all the windows. So first time Alexs deed must be choosen and so on. If you follow to this way you can get this formula for k=m.

problablity=1/(k+1);



Edited by author 17.08.2008 17:12

Edited by author 17.08.2008 17:13
Re: Please check my program. I got WA
Послано Vedernikoff Sergey (HSE: EconomicsForever!) 17 авг 2008 17:18
Your formulae for the case k > m is not right...
Re: Please check my program. I got WA
Послано SoSimple 17 авг 2008 17:23
Can You give an example test
Re: Please check my program. I got WA
Послано kai_99 17 авг 2008 17:25
void solve (int p)
{   float q;
     if (a[p].alex==a[p].bob) q=1.0/(a[p].alex+1.0);
     else  q=a[p].alex/(a[p].bob+a[p].alex);
     cout<<q<<endl;}

Where am I wrong?
Re: Please check my program. I got WA
Послано Vedernikoff Sergey (HSE: EconomicsForever!) 17 авг 2008 17:27
Take almost any example and explore it. For example, your formula gives wrong answer on the input k=3 and m=2.
Re: Please check my program. I got WA
Послано kai_99 17 авг 2008 17:29
What`s the right answer?

Edited by author 17.08.2008 17:31
Re: Please check my program. I got WA
Послано SoSimple 17 авг 2008 17:29
m>k the answer is 0;
Re: Please check my program. I got WA
Послано kai_99 17 авг 2008 17:30
Are you sure?
thanks Vedernikoff Sergey (HSE: EconomicsForever!)
Послано SoSimple 17 авг 2008 17:36
thanks Vedernikoff Sergey (HSE: EconomicsForever!). I was wrong for this case. The answer is 0.5 for your test not 3/5.
Re: thanks Vedernikoff Sergey (HSE: EconomicsForever!)
Послано kai_99 17 авг 2008 17:38
SoSimple писал(a) 17 августа 2008 17:36
thanks Vedernikoff Sergey (HSE: EconomicsForever!). I was wrong for this case. The answer is 0.5 for your test not 3/5.

Why?How?
Re: thanks Vedernikoff Sergey (HSE: EconomicsForever!)
Послано Dimon Mordvinov 17 авг 2008 17:42
I think that if k>m then the answer doesn`t depend on k, isn`t it?
Re: thanks Vedernikoff Sergey (HSE: EconomicsForever!)
Послано SoSimple 17 авг 2008 18:02
if k>m  Probability=(k-m+1)/(k+1)
Re: thanks Vedernikoff Sergey (HSE: EconomicsForever!)
Послано mai7 17 авг 2008 23:28
How did you get it? Do you divide nubmer of successive sequences to number of possibe sequences?
Re: thanks Vedernikoff Sergey (HSE: EconomicsForever!)
Послано SoSimple 19 авг 2008 17:34
Yes I have found it by this way
Re: thanks Vedernikoff Sergey (HSE: EconomicsForever!)
Послано Denis Koshman 8 сен 2008 03:54
You may think of it as of number of paths from (0;0) to (k;m) which do not cross main diagonal. There are a total of C(x, x+y) paths. If you try to find recurrent formula for f(x,x), you'll see that it is some sort of convolution over f(1)...f(x-1) which usually refers to Cathalan numbers (Sk = C(x, 2x) / (x+1)), so they are a good guess. Actually f(x,x) = Sx, it can be proven by induction. So, the probability for f(x,x) is 1/(x+1). Probability for f(x,y), y>x can be guessed and proven by induction as well. The general recurrent formula is:
f(x,y) = f(x-1,y) + f(x,y-1) for x>0, y>x
f(x, x) = f(x-1, x) for x>0
f(0,y) = 1 for y>=0

Edited by author 08.09.2008 03:58