bestcoder lines

2024-02-11 16:38
文章标签 bestcoder lines

本文主要是介绍bestcoder lines,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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(1T100)(the data for N>100 less than 11 cases),indicating the number of test cases.
Each test case begins with an integer N(1N105),indicating the number of lines.
Next N lines contains two integers Xi and Yi(1XiYi109),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

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <algorithm>
using namespace std;const double EPS=1e-8;
const int MAXN=1000000+5;
int a[MAXN*2], b[MAXN*2];struct node
{int star, en;
} len[MAXN];int bs(int a[], int l, int r, int x)
{int mid = (l+r) / 2;while(a[mid] != x){if(a[mid] > x) {r = mid;}else if(a[mid] < x) {l = mid;}mid = (l+r)/2;}return mid;
}
int main()
{int cases, n, i;scanf("%d", &cases);while(cases--){int cnt = 0, maxx = 0;memset(a, 0, sizeof(a));memset(b, 0, sizeof(b));scanf("%d", &n);for(i = 0; i < n; i++){scanf("%d %d", &len[i].star, &len[i].en);a[cnt++] = len[i].star;a[cnt++] = len[i].en;}sort(a, a+cnt);int p = 1;for(i = 1; i < cnt; i++){if(a[i] != a[i-1])a[p++] = a[i];}cnt = p;for(i = 0; i < n; i++){int mid = bs(a, 0, cnt, len[i].star);b[mid] += 1;mid = bs(a, 0, cnt, len[i].en);b[mid+1] += -1;}int ans = b[0];for(i = 1; i < cnt; i++){b[i] = b[i-1]+b[i];if(b[i] > ans)ans = b[i];}printf("%d\n", ans);}return 0;
}



这篇关于bestcoder lines的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/700290

相关文章

随机算法 - HNU 13348 Finding Lines

Finding Lines Problem's Link:  http://acm.hnu.cn/online/?action=problem&type=show&id=13348&courseid=0   Mean:  给你平面上1e5个点,让你判断是否可以找到一条直线,使得p%的点都在这条直线上。 analyse: 经典的随机算法题。 每次随机出两个点,

Halcon提取边缘线段lines_gauss 算子

Halcon提取边缘线段lines_gauss 算子 edges_color_sub_pix和edges_sub_pix两个算子使用边缘滤波器进行边缘检测。还有一个常用的算子lines_gauss算子,也可以用于提取边缘线段,它的鲁棒性非常好,提取出的线段类型是亚像素精度的XLD轮廓。其原型如下: lines gauss(Image : Lines : Sigma, Low, High, Li

Codeforces Round #329 (Div. 2) B. Anton and Lines ([好题] 计算直线在区间是否有交点)

题目链接 题意:给出n个条直线,然后在指定的区间(x1,x2)是否有直线的交点存在。 解法:一:闭区间,首先把区间略微调小。 二:计算直线在x1,x2上的交点y坐标,以及直线的id,然后按照y值,id值排序,最后判断第x1,x2左右两边的第i个点是不是同一直线的,如果不是,就存在交点。 #include<bits/stdc++.h>using namespace std;const i

BestCoder Round #62 (div.2)Clarke and five-pointed star(极角排序,判断五边形)

题目链接 题意:给你五个点,问这五个点是否可以组成正五边形(正五角星,等价于正五边形)。 解答:先极角排序,(让五个点按照顺时针或者逆时针的顺序)然后我们计算五条边是不是一样,然后在看对角线是不是都一样。 #include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<set>#includ

BestCoder Round #62 (div.2)Clarke and food (简单贪心)

题目链接 题意:有个背包容量是V,现在有n个物品,每个物品有一个体积,问背包最多能装多少个。 解法:先排序,从小到大选。 #include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<set>#include<map>#include<string>#include<cstring>

BestCoder Round #42(3/4)

http://acm.hdu.edu.cn/showproblem.php?pid=5232 Shaking hands Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 169    Accepted Submission(s):

BestCoder Round #47 ($) HDU 5280 Senior\'s Array

http://acm.hdu.edu.cn/showproblem.php?pid=5280 考少年——报考杭州电子科技大学计算机学院  Senior's ArrayTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 244

--bestcoder

Untitled Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 774    Accepted Submission(s): 423 Problem Description There is an integer  a and n i

BestCoder #47 10011002

【比赛链接】clikc here~~ ps:真是wuyu~~做了两小时,A出两道题,最后因为没加longlong全部被别人hack掉!,最后居然不知道hack别人不成功也会掉分,还一个劲的hack 别人的代码,昨天真是个悲催的比赛,~~~~(>_<)~~~~,下面弱弱献上代码~~ 1002比1001还简单~~ 1002  Senior's Gun /*BestCoder Round

POJ 1269 Intersecting Lines(判断直线相交)

题目地址:POJ 1269 直接套模板就可以了。。。实在不想自己写模板了。。。写的又臭又长。。。。不过这题需要注意的是要先判断是否有直线垂直X轴的情况。 代码如下: #include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>