# encoding=utf-8 ''' Input description : The input consists of five lines. The first line includes an integer n (2 <= n <= 50), which represents the number of rectangles. The second line includes n integers x1[i] (-10^9 <= x1[i] <= 10^9), which represent the abscissa of the lower left corner. The third line includes n integers y1[i] (-10^9 <= y1[i] <= 10^9), which represent the ordinate of the lower left corner. The fourth line includes n integers x2[i] (-10^9 <= x2[i] <= 10^9), representing the abscissa of the upper right corner. The fifth line includes n integers y2[i] (-10^9 <= y2[i] <= 10^9), which represent the ordinate of the upper right corner. Output description : output a positive integer , indicating how many rectangles overlap each other in the most places , if the rectangles do not overlap each other , output 1 . Example 1 input 2 0 90 0 90 100 200 100 200 output 2 ''' import sys lines = sys.stdin.readlines() #read multiple lines at a time n = int (lines[ 0 ]) x1 = list ( map ( int , lines[ 1 ].split())) # map batch processing y1 = list ( map ( int , lines[ 2 ].split())) x2 = list(map(int, lines[3].split())) y2 = list ( map ( int , lines[ 4 ].split())) print (x1 + x2) # [0, 90, 100, 200] list addition print (y1 + y2) # [0, 90, 100, 200] print x1 # [0, 90] res = 1 for x in x1+x2: # Determine the maximum number of intersections between the lower left or upper right corner of each rectangle and every other rectangle for y in y1+y2: cnt = 0 #For the lower left corner and upper right corner, judge independently, max takes the largest value for i in range (n): if x > x1[i] and y > y1[i] and x <= x2[i] and y <= y2[i]: #If there is a common area, the abscissa must be greater than x1 , less than or equal to x2 , and the ordinate is greater than y1 , less than or equal to y2 cnt += 1 res = max (res , cnt) print (res) # ctrl + d to end the input # run->stop
Interview question: How many rectangles overlap each other in the most places python implementation
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324507143&siteId=291194637
Recommended
Ranking