boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Palantir面经2
相关主题
请教一道算法题
问一道精华帖的老题
为什么我这段简单的程序segment fault
贡献Rocket Fuel 4 hour online test
急求rocket fuel 3小时的online test!!!
谁帮我看看这个8皇后问题
FB电面求分析 (转载)
G家 onsite 面经
神奇的一天,两据信+一个offer
Palantir新鲜面经
相关话题的讨论汇总
话题: segment话题: include话题: int话题: output话题: i2
进入JobHunting版参与讨论
1 (共1页)
s******e
发帖数: 108
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]
b*****c
发帖数: 1103
2
赞,sort+merge
f*******t
发帖数: 7549
3
interval tree?
B*******1
发帖数: 2454
4
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]

g*****i
发帖数: 2162
5
不用interval tree, linear扫一遍就可以了.楼主给的output确实错了,呵呵.
话说palantir待遇如何有人知道吗?
k****n
发帖数: 369
6
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]

l*********y
发帖数: 142
7
#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
j********x
发帖数: 2330
8
太傻比了。。。
(你问的问题比我简单多了),我遇到的都是些没啥深度的问题。。。
我问的问题比你简单多了。。。

【在 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]

1 (共1页)
进入JobHunting版参与讨论
相关主题
Palantir新鲜面经
msft校园面经 amazon三次电面面经
[合集] G家onsite面经
Palantir 面经有没有
求palantir onsite 面经
本版常见单字母IT公司全称
palantir 面经
Palantir Embedded Analyst面经
求Turn和Palantir onsite面经
新鲜SDET M onsite 面经 [update offer]
相关话题的讨论汇总
话题: segment话题: include话题: int话题: output话题: i2