Sunday, 2 March 2014

PROBLEM #7



Read the problem statement carefully.

Problem statement: One of the our DCL 2014 team’s member Aman Sharma is interested in the girl living in the building (girl’s hostel) opposite to his building (boy’s hostel). Aman Sharma wants to talk that girl but there is network problem today. SO clearly there is no source of communication (that is no mobile or internet). So Aman Sharma use his 3rd standard project called “PLAY TELEPHONE” (shown in the picture below) to communicate with girl.


                                                                        
Now the other boys and girls also starts communicate with each other with this method. As a result there is web of different strings or wires (as shown in picture below) creating lots of disturbances in the signal. “THERE IS A DISTURBANCE IN THE SIGNAL IF TWO STRINGS INTERSECT WITH EACH OTHER.”


You have been given the “INTEGER” height of each end of string from bottom of two buildings. Now your task is to find out the no of disturbances (that is no of intersections) in the strings.
NOTE: one boy or girl is communicating with only one person girl or boy respectively.

INPUT: line 1 contains an integer no ‘N’ denotes the total no. of strings or total no. of play telephones.
              Next ‘N’ lines contain two variables (Ai, bi) height of string or wire from bottom of girls & boys hostel’s building.
OUTPUT: NO. Of intersection points you see.


SAMPLE Case 1:-INPUT- 3
                   2          9
                                 4          4                     
                            5         5

                  OUTPUT- 2

 Explanation: N=3, means there are three wires or string (see picture below). The next three lines contain integer height of wire from bottom of buildings. That means wire one has height 2 at one end 9 at other end from the bottom. Similarly 2nd and 3rd wire has height of 4 and 5 units respectively. In this case output is 2 as you in picture that the two white circles represent intersection or disturbance points.



            Case 2:-      INPUT- 2
                                        6        6
                                        2        2
                        
                           OUTPUT- 0
                    
                          Explanation – n=2;
  A1=6, B1=6
  A2=4,B2=4
SO NO intersection, output=0

BEST OF LUCK
CODE! COMPILE! CHEER!
                       

No comments: