【C++竞赛 G】Lines
来源:互联网 发布:数据库设计说明书实例 编辑:程序博客网 时间:2024/05/24 06:18
Time Limit: 3s Memory Limit: 64MB
问题描述
Ljr has several lines. The lines are covered on the X axis. Let A is a point which is covered by the most lines. Ljr wants to know how many lines cover A.
输入描述
The first line contains a single integer T(1≤T≤100) (the data for N>100 less than 10 cases), indicating the number of test cases. Each test case begins with an integerN(1≤N≤〖10〗^5), indicating the number of lines. Next N lines contains two integers X_i and Y_i (-〖10〗^9≤X_i,Y_i≤〖10〗^9), describing a line.
输出描述
For each case, output an integer means how many lines cover A.
输入样例
2
5
1 2
2 3
2 4
3 4
5 1000
5
1 2
3 4
5 6
7 8
9 10
输出样例
3
1
【题目链接】:
【题解】
把区间端点离散化一下,然后就转换成区间最大值的问题了;
写个线段树就好;
x<=y不一定成立;
【完整代码】
#include <bits/stdc++.h>#define rep1(i,a,b) for (int i = a;i <= b;i++)using namespace std;#define pb push_back;const int MAXN = 1e5+10;int ma[MAXN*2*4],tag[MAXN*2*4];struct abc{ int l,r;};abc aa[MAXN];vector <int> a;map <int,int> dic;void push_down(int rt){ tag[rt<<1]+=tag[rt]; tag[rt<<1|1]+=tag[rt]; ma[rt<<1]+=tag[rt]; ma[rt<<1|1]+=tag[rt]; tag[rt] = 0;}void up_data(int L,int R,int l,int r,int rt){ //printf("%d %d\n",l,r); if (L<=l && r <= R) { ma[rt]++; tag[rt]++; return; } if (tag[rt]!=0) push_down(rt); int m = (l+r)>>1; if (L<=m) up_data(L,R,l,m,rt<<1); if (m<R) up_data(L,R,m+1,r,rt<<1|1); ma[rt] = max(ma[rt<<1],ma[rt<<1|1]);}int main(){ //freopen("D:\\rush.txt","r",stdin); int T; scanf("%d",&T); while (T--) { memset(ma,0,sizeof(ma)); memset(tag,0,sizeof(tag)); dic.clear(); a.clear(); int n; scanf("%d",&n); rep1(i,1,n) { scanf("%d%d",&aa[i].l,&aa[i].r); if (aa[i].l>aa[i].r) swap(aa[i].l,aa[i].r); if (!dic[aa[i].l]) { a.push_back(aa[i].l); dic[aa[i].l] = 1; } if (!dic[aa[i].r]) { a.push_back(aa[i].r); dic[aa[i].r] = 1; } } sort(a.begin(),a.end()); rep1(i,1,n) { int l,r; l = lower_bound(a.begin(),a.end(),aa[i].l)-a.begin()+1; r = lower_bound(a.begin(),a.end(),aa[i].r)-a.begin()+1; up_data(l,r,1,MAXN<<1,1); } printf("%d\n",ma[1]); } return 0;}
- 【C++竞赛 G】Lines
- [算法竞赛入门经典] UVA 1471 - Defense Lines
- lines
- 河南省第十届大学生程序设计竞赛 A,B,C,D,F,G,H 题解
- 【哈尔滨理工大学第七届程序设计竞赛决赛(高年级组)】 A B C D E G
- 【20160327】"尚学堂杯"哈尔滨理工大学第六届程序设计竞赛A.B.C.D.E.G题解
- 【哈尔滨理工大学第七届程序设计竞赛初赛(高年级组)】 A B C D F G H I
- 1059. C语言竞赛
- 1059. C语言竞赛
- 1059. C语言竞赛
- 1059. C语言竞赛
- 湖南省第八届程序设计竞赛G
- 福州大学第十二届程序设计竞赛-G - Escape
- g++ -o -c -g 功能
- Memo1->Text与Memo1->Lines的关系(C++Builder)
- 【模拟 计算几何】连线游戏 lines.pas/c/cpp
- [C]simple code of count input lines,words,chars
- ROS学习笔记(五)::RVIZ:Markers::Points and Lines (C++)
- MySQL数据库高可用性架构汇总
- 【矩阵分解】Python下基于Numpy的四种矩阵基本分解的实现
- 数据结构与算法(序)
- Java学习路线图
- c++ primer第五章练习题总结
- 【C++竞赛 G】Lines
- ios 两个时间之间的比较,相差多少天多少小时多少分多少秒
- 继承
- 单链表的实现。
- 数据库索引
- 第十三周项目四-Floyd算法验证
- Python3 C扩展
- linux压缩或解压缩命令
- 《机器学习实战》——决策树代码