Count rectangles generated in a given rectangle by lines drawn parallel to X and Y axis from a given set of points | C # program to implement the above approach ; Function to get the count of ractangles ; Store distinct horizontal lines ; Store distinct Vertical lines ; Insert horizontal line passing through 0 ; Insert vertical line passing through 0. ; Insert horizontal line passing through rectangle [ 3 , 0 ] ; Insert vertical line passing through rectangle [ 3 , 1 ] ; Insert all horizontal and vertical lines passing through the given array ; Insert all horizontal lines ; Insert all vertical lines ; Driver Code
using System ; using System . Collections . Generic ; class GFG { public static int cntRect ( int [ , ] points , int N , int [ , ] rectangle ) { HashSet < int > cntHor = new HashSet < int > ( ) ; HashSet < int > cntVer = new HashSet < int > ( ) ; cntHor . Add ( 0 ) ; cntVer . Add ( 0 ) ; cntHor . Add ( rectangle [ 3 , 0 ] ) ; cntVer . Add ( rectangle [ 3 , 1 ] ) ; for ( int i = 0 ; i < N ; i ++ ) { cntHor . Add ( points [ i , 0 ] ) ; cntVer . Add ( points [ i , 1 ] ) ; } return ( cntHor . Count - 1 ) * ( cntVer . Count - 1 ) ; } public static void Main ( String [ ] args ) { int [ , ] rectangle = { { 0 , 0 } , { 0 , 5 } , { 5 , 0 } , { 5 , 5 } } ; int [ , ] points = { { 1 , 2 } , { 3 , 4 } } ; int N = points . GetLength ( 0 ) ; Console . WriteLine ( cntRect ( points , N , rectangle ) ) ; } }