avatar
Shipping update for N4# PDA - 掌中宝
s*e
1
Given 2 range array, output the intersection array.
a: [1,5], [8,15], [30,90]
b: [2,7],[12,18],[80,100]
output:
[2,5],[12,15],[80,90]
avatar
m*g
2
没有delivery estimate
avatar
b*c
3
赞,sort+merge
avatar
c*c
4
中国移动?
avatar
f*t
5
interval tree?
avatar
m*g
6
哦,我也可以改成中国联通,呵呵。

【在 c*c 的大作中提到】
: 中国移动?
avatar
B*1
7
isn't it
output:
[2,5],[12,15],[80,90]

【在 s******e 的大作中提到】
: Given 2 range array, output the intersection array.
: a: [1,5], [8,15], [30,90]
: b: [2,7],[12,18],[80,100]
: output:
: [2,5],[12,15],[80,90]

avatar
g*i
8
不用interval tree, linear扫一遍就可以了.楼主给的output确实错了,呵呵.
话说palantir待遇如何有人知道吗?
avatar
k*n
9
are they sorted?

【在 s******e 的大作中提到】
: Given 2 range array, output the intersection array.
: a: [1,5], [8,15], [30,90]
: b: [2,7],[12,18],[80,100]
: output:
: [2,5],[12,15],[80,90]

avatar
l*y
10
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
struct Segment {
int from, to;
};
struct cmp {
bool operator() (const Segment& s1, const Segment& s2) {
return s1.from < s2.from;
}
};
bool GetOverlap(Segment& s1, Segment& s2, Segment& inter)
{
bool result = false;
if (s1.to > s2.from && s2.to > s1.from) {
result = true;
inter.from = max(s1.from, s2.from);
inter.to = min(s1.to, s2.to);
}
return result;
}
int main() {
freopen("input","r",stdin);
int numofcase;
cin >> numofcase;
for (int cc = 1; cc <= numofcase; cc++) {
vector v1;
vector v2;
Segment segment;
int index, num;
cin >> index;
for (int i = 0; i < index; i++) {
cin >> segment.from >> segment.to;
v1.push_back(segment);
}
cin >> index;
for (int i = 0; i < index; i++) {
cin >> segment.from >> segment.to;
v2.push_back(segment);
}
sort(v1.begin(), v1.end(), cmp());
sort(v2.begin(), v2.end(), cmp());
int i1 = 0;
int i2 = 0;
vector result;
while (i1 < v1.size() && i2 < v2.size()) {
Segment inter;
if (GetOverlap(v1[i1], v2[i2], inter)) {
result.push_back(inter);
}
if (v1[i1].to <= v2[i2].to) {
i1++;
} else {
i2++;
}
}
for (int i = 0; i < result.size(); i++) {
cout << result[i].from << " " << result[i].to << endl;
}
}
return 0;
}
Input:
1
3 1 5 8 15 30 90
3 2 7 12 18 80 100
Output:
2 5
12 15
80 90
avatar
j*x
11
太傻比了。。。
(你问的问题比我简单多了),我遇到的都是些没啥深度的问题。。。
我问的问题比你简单多了。。。

【在 s******e 的大作中提到】
: Given 2 range array, output the intersection array.
: a: [1,5], [8,15], [30,90]
: b: [2,7],[12,18],[80,100]
: output:
: [2,5],[12,15],[80,90]

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。