/* Gains: greedy + switching */# include <iostream> # include <cstdlib> # include <vector> # include <map> # include <cstring> # include <string> # include <algorithm> # include <sstream> # include <ctype. h> # include <fstream> # include <string. h> # include <stdio. h> # include <math. h> # include <stack> # include <queue> # include <ctime> // # include <conio. h> using namespace STD; const int inf_max = 0x7fffff; const int inf_min =-(1 <31); const double EPS = 1e-10; const Double Pi = ACOs (-1.0); # define Pb push_back // A. Pb () # define chmin (A, B) (a) <(B )? (A) :( B) # define chmax (A, B) (a)> (B )? (A) :( B) template <class T> inline t gcd (t a, t B) // notes: gcd ({if (a <0) return gcd (-a, B); If (B <0) return gcd (A,-B); Return (B = 0 )? A: gcd (B, A % B);} template <class T> inline t lcm (t a, t B) // notes: lcm ({if (a <0) return lcm (-a, B); If (B <0) return lcm (A,-B); return a * (B/gcd (A, B ));} typedef pair <int, int> PII; typedef vector <PII> vpii; typedef vector <int> VI; typedef vector <VI> VVI; typedef long ll; int dir_4 [4] [2] = {}, {-}, {0,-1 }}; int dir_8 [8] [2] = {}, {-1,-1}, {0,-1 }, {1,-1}, {}, {}; // bottom, bottom left, left, top left, top right, top right, right bottom. ****************************** * ********************************* Int s [250]; int N; inline void initial () {memset (S, 0, sizeof (s); // ans = 0 ;}inline void input () {int A, B; cin> N; For (INT I = 0; I <n; I ++) {scanf ("% d", & A, & B ); if (A> B) Swap (a, B); For (Int J = (a-1)/2; j <= (B-1)/2; j ++) s [J] ++;} return;} inline void output () {int ans = 0; For (INT I = 0; I <= 200; I ++) ans = chmax (ANS, s [I]); cout <ans * 10 <Endl; return;} int main () {// freopen ("input.txt", "r", stdin); // freopen ("output.txt", "W", stdout); int t; CIN> T; while (t --) {initial (); input (); output () ;}// printf ("%. 6f \ n ", (double) Clock ()/clocks_per_sec );}
Click Open Link
This is a greedy algorithm.
My practice is: for each line segment, there are start and end, referred to as S, E, to create a node struct, and then sort these struct, according to E from small to big. Then, take the largest e line segment, referred to as a, and find a relatively largest e smaller than the start of.
Difficulty: Determine the Second E. If the binary method is adopted, the complexity is: N line segments, log (n) * n; if the sequential search is adopted, the complexity is: N ^ 2;
Answer: This question has only 200 pieces of data. Therefore, if you add a line segment, add 1 to the line segment, and finally select the largest point in the middle of the line segment. The complexity is 200 * n;
Code: