HDU 5124

题意:给定 n 个区间,问最多重复的子区间?

题解:(离散化思想)讲所有的数都排个序,将区间的左值定为 1 ,右值定为 -1 ,这样对所有的数搜一遍过去找最大的值即可

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <stdlib.h>
 4 #include <math.h>
 5 #include <time.h>
 6 #include <ctype.h>
 7 #include <string>
 8 #include <queue>
 9 #include <set>
10 #include <map>
11 #include <stack>
12 #include <vector>
13 #include <algorithm>
14 #include <iostream>
15 #define PI acos( -1.0 )
16 using namespace std;
17 typedef long long ll;
18
19 const int NO = 1e5 + 10;
20 struct ND
21 {
22     int x, y;
23 }st[NO<<1];
24 int n;
25
26 bool cmp( const ND &a, const ND &b )
27 {
28     if( a.x == b.x ) return a.y > b.y;
29     return a.x < b.x;
30 }
31
32 int main()
33 {
34     int T;
35     scanf( "%d",&T );
36     while( T-- )
37     {
38         scanf( "%d", &n );
39         int cur = 0;
40         for( int i = 0; i < n; ++i )
41         {
42             scanf( "%d", &st[cur].x );
43             st[cur++].y = 1;
44             scanf( "%d", &st[cur].x );
45             st[cur++].y = -1;
46         }
47         sort( st, st+cur, cmp );
48         int ans = 0;
49         int Max = 0;
50         for( int i = 0; i < cur; ++i )
51         {
52             ans += st[i].y;
53             Max = max( ans, Max );
54         }
55         printf( "%d\n", Max );
56     }
57     return 0;
58 }

时间: 2024-10-12 03:31:38

HDU 5124的相关文章

【扫描线】HDU 5124 lines

http://acm.hdu.edu.cn/showproblem.php?pid=5124 [题意] 在数轴x上,每次操作都覆盖一个区间的所有点,问被覆盖次数最多的点是覆盖了多少次 [思路] 最简单的扫描线,左右端点分别排序,遇到左端点sum++更新最值,遇到右端点sun--更新最值 [Accepted] 1 #include<bits/stdc++.h> 2 using namespace std; 3 int a[100010],b[100010]; 4 int t,n; 5 bool

BestCoder20 1002.lines (hdu 5124) 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124 题目意思:给出 n 条线段,每条线段用两个整数描述,对于第 i 条线段:xi,yi 表示该条线段的左端点和右端点.设 A 表示最多线段覆盖的点(当然这个 A 可以有多个啦,但这个无关紧要).现在需要求的是 A 被多少条线段覆盖. 我是不会做啦.......一开始还看不懂题目= = 以下是按照题解做的, 题解中的最大区间和,实际上就是求最大连续子序列的和. 1 #include <iostrea

HDU 5124 lines(BestCoder Round #20)

Problem Description: John has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. John wants to know how many lines cover A. Input: The first line contains a single integer T(1≤T≤100)(the data for 

hdu 5124 lines (线段树+离散化)

lines Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 620    Accepted Submission(s): 288 Problem Description John has several lines. The lines are covered on the X axis. Let A is a point which

HDU 5124 lines

lines Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 515    Accepted Submission(s): 241 Problem Description John has several lines. The lines are covered on the X axis. Let A is a point which i

[思路题] hdu 5124 lines

题意: 给n个区间 [x,y],问被最多覆盖的点,被覆盖了多少次. 思路: 一个很巧妙的方法.好像原来有接触过. 就是如果给你[1,3]就used[1]++,used[4]--. 然后从左到又过一遍出现的点 依次累加每次加的时候取最大值. 然后这题需要用到map离散化. 代码: #include"cstdlib" #include"cstdio" #include"cstring" #include"cmath" #inclu

hdu 5124 lines(Bestcoder Round #20)

lines                                                                Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 309    Accepted Submission(s): 145 Problem Description John has several line

hdu 4325 Flowers(区间离散化)

http://acm.hdu.edu.cn/showproblem.php?pid=4325 Flowers Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2633    Accepted Submission(s): 1290 Problem Description As is known to all, the blooming t

BestCoder Round #20 解题报告 A.B.C.

A题:who is the best? 题目地址:HDU 5123 水题. 哈希,然后枚举找最大的,从小的开始找. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <queu