MohamedHassan499's blog

By MohamedHassan499, history, 5 years ago, In English

I tried so solve this problem using two pointer technique but I'm getting some precision error in the last test in this code, Is it a precision error, or there's something my code isn't handling, or my logic from the very beginning is wrong?

And thank you for your time.

Full text and comments »

By MohamedHassan499, history, 5 years ago, In English

You're given a number $$$n$$$ It may be prime or not, It's required from you to get 4 positive prime numbers at which their summition equals to $$$n$$$, and if this isn't possible, then state that (There's more that one test cast BTW).

My approach was to get all prime numbers form 2 to 10000000 using sieve theory only once, and to try assume 3 of these numbers and get every possible combination of 2's and 3's (Assuming that all prime numbers can be deduce from summition of these two) let these numbers are $$$x$$$, $$$y$$$ and $$$z$$$ and if there exist a fourth number at which this 4th number = n - x + y + z and If it's positive and prime, then we found the answer otherwise this won't be possible.

If there's something wrong with my approach? If not there's the mistake in my code Link to the problem is here

Full text and comments »

By MohamedHassan499, 5 years ago, In English

Problem statement

Two friends Kunal and Satyam are playing an interesting game. They take turns drawing a ball from a bag which initially contains R red balls and G green balls. Each player draws a ball alternatively and never put it back. The person who is the first to draw a red balls wins. Satyam always draws first. If there are no more balls in the bag and nobody has drawn a red ball, the satyam wins.

Input -----

The first line will contain the number of test cases T. The first line of each test case will contain a number R (number of red balls) and G(number of green balls )

Cases:

2 1 --> 0.6666667 1 1 ---> 0.50000 10 0 ----> 1.0000

problem link is here:

I tired to solve the problem using top-bottom approach but my codes gives wrong answer at the last case (0 instead of 1)

int probability = 0, c = 0;

void magic(int red, int green, int turn){
	if(green == -1 || red == -1)return ;
	if(red == 0){
		probability++;
		if(turn % 2 == 0) c++;
		return ;
	}
	if(turn == -1) turn = 0;
	else turn++;
	magic(red, green-1, turn % 2);
	magic(red-1, green, turn % 2); 
	return ;
}

int main(){
     
 	ios::sync_with_stdio(0);
    cin.tie(nullptr);
     
    int q;
    cin >> q;
    while(q--){
    	int x, y;
    	cin >> x >> y;
    	magic(x, y, -1);
    	cout << fixed << setprecision(9) << c * 1.0 / probability << '\n';
    	probability = 0, c = 0;
    }
    return 0;
}

I will appreciate any kind of help from all of you, and thanks for your time

Full text and comments »

Tags dp
By MohamedHassan499, history, 5 years ago, In English

When I enter my submission page and click in my submission IDs, It doesn't work with me, and so when I enter a problem like and click on my submissions the "Click here to see details" doesn't work too!

  • Another problem, I have submittied a problem called CME form yesterday and It got accepted at 31 ms and now I submitted the same exact code and got accepted at 46 ms!

Does someone else have the same Issue as mine?

Full text and comments »

  • Vote: I like it
  • +6
  • Vote: I do not like it

By MohamedHassan499, history, 5 years ago, In English

Hi everyone,

This problem gives you two inputs N, M and N contains a number like (123) and all what you have to do is to add some digits on the left or the right of the (123) to make it divisible by M Hint about solving this problem, Or a solution for It?

constrains :- N<= 10^12 and M <= 2 * 10^5

Sample tests:-

(Test 1) 1 2 ===> 10 (Test 2) 2 11 ===> 22 (Test 3)234 823 ===> 12345

problem link: https://www.urionlinejudge.com.br/judge/en/problems/view/2788

And thanks In advance. :)

Full text and comments »

  • Vote: I like it
  • +5
  • Vote: I do not like it

By MohamedHassan499, history, 5 years ago, In English

I has been 6 months since I start to solve problems from any online judge (Codeforces was the first one by the way) but since then, I barely notice a difference in my problem solving skills from now and 6 months ago even I had solve +100 problem and every time I register in a contest (div 2 or 3), my rate always decreases by -90 or more, and even If I managed to solve a problem It would be an A only.

So what should I do to improve my self even more? or begin a professional problem-solver requires lot of years practising? I'll be very grateful If you recommeded a few solutions based on your experience ^^

Thanks in advance.

Full text and comments »