DR.MANHATTAN's blog

By DR.MANHATTAN, 7 years ago, In English

Highlight: Successfully did Problem — B, but failed to do Problem — A( Awkward !! )

I remember the first time I'd been to an onsite contest ( almost 1 year ago ), the drive to solve the questions the fastest was so high that my brain and my hands literally got paralyzed and I was unable to do anything after attempting the First Question. Thanks to my team mate, we still managed to get the 3rd place and a Cash prize with it ( sweet !! ). What's sad, is that I did not lack in knowledge or skill to solve all the problems in time ( It was not a hard contest ) and could have easily managed to get the first prize and some SERIOUS BOUNTY !!

However, winning the 3rd prize too got me enough bounty to buy this beauty for myself !!

Since then, thanks to Petr and his YouTube contest Video's Petr's competitive programming video with commentary , I've learned the art of staying calm during a contest and got rid of a HUGE limitation.

Contest Talk :

Problem A The question seemed pretty clear, but it seemed confusing as to how to go about it. (_Fun Fact_: this was the first contest I'd seen in which more people got the Problem B right than the number of people that got Problem A right.) So I was not alone in this conundrum. The limits (b<=10^7 and a<=10^7) ensured that a brute force solution was not gonna work. My initial solution did pass the pre-tests, but was hacked in an instant. I understood how to go about the problem only after reading the official editorial.

Problem B Yay!! A geometry problem (barely though!!). After my initial solution for Problem A got hacked, I moved on the problem B and couldn't contain my happiness when I found out that it was a geometry problem and one that I could perhaps SOLVE !! There is something magical about geometry problems!! Perhaps it's because of the images that you form in your mind while solving the problem, the thought process or the imagination that goes into it that if feels kinda STAR-TRECKY !!

When you finally solve a geometry problem ( or at least when I solve one ) It almost feels like I've solved one of the problems that the Star Trek spacecraft encountered along one of its many fantastical voyages :D

However, this question had a pizza (Yum!!) in context, but it was still enjoyable to solve. The picture used for explanation was spot on (though I only saw it after I'd already solved and submitted the solution )

All one had to do was to ensure that the toppings were right within the boundary of the crust. The handy Pythagoras theorem helped to determine the distance of the center of the topping from the origin, subtracting and adding the x coordinate value of the topping to the resulting hypotenuse and checking that the line was within the given boundary ( crust ) ensured that only the right toppings were counted!

int  length(double x,double y,double r_s,double r,double d){
     	double hyp=sqrt(x*x+y*y);
     	return (hyp-r_s>=(r-d) && hyp+r_s<=r);
     }

     int main(){fastio

     	int r,d;
     	cin>>r>>d;
     	int ct=0;
     	test(t){

     		double x,y,r_s;
     		cin>>x>>y>>r_s;

     		if(length(x,y,r_s,r,d))ct++;
     	}


     	cout<<ct;
     }

Got AC in first go !!

My rating too went up thanks to this problem !! ---------- Rest of the problems were beyond the reach of my knowledge as they were topics from Trees and Tries .. etc ... Will get there one day... !!

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