http://acm.hdu.edu.cn/showproblem.php?pid=5124

lines

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1362    Accepted Submission(s): 566

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 N>100 less than 11 cases),indicating the number of test cases.
Each test case begins with an integer N(1≤N≤105),indicating the number of lines.
Next N lines contains two integers Xi and Yi(1≤Xi≤Yi≤109),describing a line.
 
Output
For each case, output an integer means how many lines cover A.
 
Sample Input
2
5
1 2
2 2
2 4
3 4
5 1000
5
1 1
2 2
3 3
4 4
5 5
 
Sample Output
3
1
 
Source
 
一个离散化, 我也是醉了, 怎么就搞不懂了。。。。
 
这题居然能不用离散化, 暴力水过, 还是会离散化好点, 但是这个水代码也粘贴下吧!!!
 
#include<stdio.h>
#include<string.h> #define N 1100000
#define max(a,b) (a>b?a:b) int a[N]; int main()
{
int T; scanf("%d", &T); while(T--)
{
int n, i, L, R; scanf("%d", &n);
memset(a, , sizeof(a)); for(i=; i<=n; i++)
{
scanf("%d%d", &L, &R);
a[L] ++;
a[R+] --;
} int Max = a[], sum=a[]; for(i=; i<N; i++)
{
sum += a[i];
Max = max(Max, sum);
} printf("%d\n", Max);
} return ;
}

水过代码

下面两个代码都是用了离散化, 但是其实我并不怎么懂离散化, 只懂了一点点, 继续学习吧!!!

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define N 201000 struct node
{
int L, R;
}a[N]; int b[N], V[N]; int main()
{
int T; scanf("%d", &T); while(T--)
{
int i, L, R, n, k=; scanf("%d", &n); memset(a, , sizeof(a));
memset(b, , sizeof(b));
memset(V, , sizeof(V)); for(i=; i<n; i++)
{
scanf("%d%d", &a[i].L, &a[i].R);
b[k++] = a[i].L;
b[k++] = a[i].R;
} sort(b, b+k); int z = unique(b, b+k)-b; for(i=; i<n; i++)
{
L = lower_bound(b, b+z, a[i].L) - b;
R = lower_bound(b, b+z, a[i].R) - b;
V[L]++;
V[R+]--;
} int sum=V[], Max = V[];
for(i=; i<N; i++)
{
sum += V[i];
Max = max(Max, sum);
} printf("%d\n", Max);
}
return ;
}
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map> using namespace std; #define N 200005 struct node
{
int L, R;
}a[N]; int V[N], b[N]; map<int, int>dic; int main()
{
int T;
scanf("%d", &T);
while(T--)
{
int i, j, k=, n, L, R; scanf("%d", &n); memset(a, , sizeof(a));
memset(V, , sizeof(V));
memset(b, , sizeof(b)); for(i=; i<n; i++)
{
scanf("%d%d", &a[i].L, &a[i].R);
b[k++] = a[i].L;
b[k++] = a[i].R;
} sort(b, b+k);
j=;
for(i=; i<k; i++)
{
if(i==)
dic[b[i]]=j++;
else if(b[i]!=b[i-])
dic[b[i]]=j++;
} for(i=; i<n; i++)
{
L = dic[a[i].L];
R = dic[a[i].R];
V[L]++;
V[R+]--;
} int Max = V[], sum = V[]; for(i=; i<N; i++)
{
sum += V[i];
Max = max(Max, sum);
} printf("%d\n", Max);
}
return ;
}

最新文章

  1. zerojs! 造出最好的 CMS 轮子
  2. 机器学习实战笔记(Python实现)-05-支持向量机(SVM)
  3. placehoder不兼容ie9以下和opero12以下
  4. ArcGIS 的 Oracle 数据库的要求
  5. [.NET]二维码生成
  6. linux命令(6):rmdir 命令
  7. poj1375Intervals(点到圆的切线)
  8. goldengate 12c对teradata的支持
  9. cocos2d-x中有一个JniHelper类详细使用
  10. HTML+CSS学习笔记 (7) - CSS样式基本知识
  11. C#中is、as的区别
  12. is not mapped 解决方法
  13. c# winfrom 委托实现窗体相互传值
  14. 《精通CSS:高级Web标准解决方案》学习笔记(上)
  15. CentOS下编译安装Gcc-4.9
  16. php中禁止非法调用和硬路径引入文件的方法
  17. 【Java】【jquery】ajax垃圾问题
  18. 升级版本后报这个异常 : org.springframework.beans.factory.NoUniqueBeanDefinitionException
  19. Vue2.0结合webuploader实现文件分片上传
  20. hdu 5514 Frogs(容斥)

热门文章

  1. linux操作系统-源码包安装jdk1.7
  2. 为Linux虚拟机设置网络
  3. Android开发之动态设置字体的样式和粗细
  4. 函数调用的四种方式 和 相关的 --- this指向
  5. nginx 启动报错 “/var/run/nginx/nginx.pid&quot; failed” 解决方法
  6. ubuntu下安装配置ADB
  7. 服务程序 -st
  8. Servlet封装类
  9. spring converter-message 规则
  10. sqlserver 数据迁移