Page 1 of 3

11061 - Playing War

Posted: Sun Aug 06, 2006 2:24 am
by Towhid
What is the idea behind the problem. I have not much studies in probability. Should I learn/ study something to solve this problem???

Re: 11061: Playing War

Posted: Sun Aug 06, 2006 2:31 am
by Martin Macko
Towhid wrote:What is the idea behind the problem. I have not much studies in probability. Should I learn/ study something to solve this problem???
I've used DP approach.

Posted: Sun Aug 06, 2006 12:22 pm
by Dreamer#1
Yes, DP works fine. Nice problem, enjoyed solving it at the contest. :D
I wish we had such nice problems in my region. :P

Posted: Sun Aug 06, 2006 10:52 pm
by sluga
Could someone give me your outputs for these inputs?

5
10
20
50
100
150
200
250
300
450
500
750
789
901
945
1000
0

Posted: Sun Aug 06, 2006 10:55 pm
by Martin Macko
sluga wrote:Could someone give me your outputs for these inputs?
My AC's output:

Code: Select all

9
18
35
86
171
257
342
428
513
770
856
1283
1350
1541
1617
1711

Posted: Sun Aug 06, 2006 10:56 pm
by sluga
Thank you very much!

Posted: Sun Aug 06, 2006 11:07 pm
by sluga
It seems my code has a bug somewhere... I was affraid it was precision error, but this is much easier to solve :)

One more question: does the opponent always use maximum allowed number of soldiers?

Posted: Sun Aug 06, 2006 11:10 pm
by Martin Macko
sluga wrote:It seems my code has a bug somewhere... I was affraid it was precision error, but this is much easier to solve :)

One more question: does the opponent always use maximum allowed number of soldiers?
Yes, both of them always use maximum allowed number of soldiers.
problem statement wrote:It should not be a surprise that usually each player uses as many armies in a combat as he can, even though the rules allow him to use less.

Posted: Sun Aug 06, 2006 11:21 pm
by sluga
got ACC, thanks

Posted: Mon Aug 07, 2006 9:29 am
by arsalan_mousavian
i got WA on this problem , can some one read my code and tell me if my approach is correct or not ?

Code: Select all

#include <iostream>
#include <cmath>
using namespace std ;
double prob [2000][1001] ;
int result [1001] ;
int main ()
{
	for ( int i=0 ; i<2000 ; i++ )
		prob [i][0] = 1 ;
	for ( int i=0 ; i<=1000 ; i++ )
		prob [1][i] = prob [0][i] = 0 ;
	for ( int attack = 2 ; attack < 2000 ; attack ++ ) 
		for ( int defend = 1 ; defend <= 1000 ; defend ++ ) 
			prob [attack][defend] = (double)(15.0/36.0)* prob[attack][defend-1] + (double) (21.0/36.0)*prob[attack-1][defend] ;
	memset ( result , 0 , sizeof result ) ;
	int X ;
	while ( cin >> X ) 
	{
		if ( !X ) break;
		if ( result [X] == 0 )
		{
			for ( int attack = 2 ; attack < 2000 ; attack ++ ) 
				if ( prob [attack][X] > 0.5 )
				{
					result [X] = attack ;
					break ;
				}
		}
		cout << result [X] << endl;

	}


}
thanks in Adavnce . . .
Arsalan

Posted: Mon Aug 07, 2006 9:51 am
by Martin Macko
arsalan_mousavian wrote:i got WA on this problem , can some one read my code and tell me if my approach is correct or not ?
Could you explain us how did you get the following formula?
arsalan_mousavian's main() wrote:.....prob[attack][defend] = (double) (15.0 / 36.0) * prob[attack][defend-1] +
.................................................. (double) (21.0 / 36.0) * prob[attack-1][defend];

Posted: Mon Aug 07, 2006 11:42 am
by arsalan_mousavian
Martin Macko wrote:
arsalan_mousavian wrote:i got WA on this problem , can some one read my code and tell me if my approach is correct or not ?
Could you explain us how did you get the following formula?
arsalan_mousavian's main() wrote:.....prob[attack][defend] = (double) (15.0 / 36.0) * prob[attack][defend-1] +
.................................................. (double) (21.0 / 36.0) * prob[attack-1][defend];
on each level they roll the dice attakers hava the probabillity of 15/36 to kill one defender ( becauese there is 15 pair of numbers between 1 and 6 that the first one is greater than the second one ) and defender has the probabilty of 21/36 to kill one attacker

Posted: Mon Aug 07, 2006 1:01 pm
by Martin Macko
arsalan_mousavian wrote:on each level they roll the dice attakers hava the probabillity of 15/36 to kill one defender ( becauese there is 15 pair of numbers between 1 and 6 that the first one is greater than the second one ) and defender has the probabilty of 21/36 to kill one attacker
Well, but in each attack both of them may use up to 3 armies, therefore on each side up to 3 armies may die in one attack.

Posted: Mon Aug 07, 2006 1:06 pm
by Mg9H
Martin Macko wrote:
arsalan_mousavian wrote:on each level they roll the dice attakers hava the probabillity of 15/36 to kill one defender ( becauese there is 15 pair of numbers between 1 and 6 that the first one is greater than the second one ) and defender has the probabilty of 21/36 to kill one attacker
Well, but in each attack both of them may use up to 3 armies, therefore on each side up to 3 armies may die in one attack.
actually there are exactly bno = min (Attack, Defense) (<= 3) battles can happen in 1 attack, and exactly that many armies (in total, counting from both side) will die.

Posted: Mon Aug 07, 2006 2:12 pm
by Towhid
Well, how the winning of a single combat is determined? I thought, in a 3 against 3 battle the combat is continued until all 3 of any side are died. But in that case there can be more than 3 battles...