Problem description H and W came to a street. They bought food separately. The process of buying food can be described, I went to the store to buy some food and then loaded the food into a car in the square next to it. Both of them had to buy n kinds of food, so they had to install n cars.
Specifically, for small h, there are N non-Intersecting time periods [A1, B1], [A2, B2]... [An, BN] when loading a car, for small W, there are n different time periods [C1, D1], [C2, D2]... [CN, DN] loading.
[S, T] indicates the period from time s to time t, and the length of time is t-s. Because they are good friends, they will chat when they are loading cars in the square. They want to know how long they can chat. The first line in the input format contains a positive integer N, indicating the number of time periods. In the next n rows, there are two pieces of AI and Bi in each row, which describe the loading time periods of small h. The next n rows have two CI, Di, and describe the loading time periods of W. The output format outputs a row. A positive integer indicates how long the two can chat. Sample input 41 35 69 1314 152 710 1113 14 sample output 3 data scale and conventions for all evaluation cases, 1 ≤ n ≤ 2000, AI <Bi <AI + 1, CI <di <Ci + 1. For all I (1 ≤ I ≤ n), 1 ≤ AI, Bi, CI, di ≤ 1000000.
The idea at the beginning is:
That is, to calculate the coincidence time, the Code is as follows, but the score obtained after submission is 10 points. Thank you for choosing the correct one. |.
Import Java. util. role; public class buyvetab {public static void main (string [] ARGs) {role SC = new role (system. in); int n = SC. nextint (); int [] A = new int [N * 2]; int [] B = new int [N * 2]; for (INT I = 0; I <n * 2; I ++) {A [I] = SC. nextint (); B [I] = SC. nextint () ;}// obtain the minimum values of A and C, and the maximum values of B and D: int secon = 0; For (INT I = 0; I <n; I ++) {int x = getmax (A [I], a [n + I]); int y = getmin (B [I], B [n + I]); if (Y-x> 0) {secon + = Y-x ;}} system. out. println (secon);} public static int getmin (int x, int y) {If (x <Y) {return X;} else {return y ;}} public static int getmax (int x, int y) {If (x> Y) {return X;} else {return y ;}}}
Then I searched for other people's solutions on the internet, thanked the internet, and thanked the great gods for their ideas. I suddenly felt the charm of the Code.
Post the solution and code of the great gods.
Import Java. util. empty; public class buy food {public static void main (string [] ARGs) {empty input = new empty (system. in); int n = input. nextint (); int [] T = new int [1000000]; int COUNT = 0; For (INT I = 0; I <n * 2; I ++) {int A = input. nextint (); int B = input. nextint (); For (Int J = A; j <B; j ++) T [J] ++;} For (int I: T) if (I> 1) count ++; system. out. println (count );}}--------------------- Aivenz Source: csdn Original: https://blog.csdn.net/AivenZhong/article/details/83343579 copyright statement: This article is the original author of the blog, reprinted Please attach a blog link!
The code is concise and the train of thought is smooth, which makes me deeply immersed in this dish.
CCF Certification: Food Purchase