您的位置:首页 > 其它

百度之星复赛Astar Round3

2016-05-29 17:06 246 查看

拍照

树状数组(SB了)。求出静止状态下,每个点能看到多少个向右开的船c1[i],多少个向左开的船c2[i]。

max{c1[i] + c2[j], (满足i <= j) }即为答案。从后往前枚举i即可。

注意要离散化,否则会Tle。

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int maxn =2e4;
int c1[maxn<<2], c2[maxn<<2];

void Add(int l, int r, int* c){
c[l]++, c[r+1]--;
}

int n;
int ope[maxn], tot;
struct p{
int l, r, d;
p(){}
p(int l, int r, int d):l(l), r(r), d(d){}
};
p pp[maxn];

int main(){
int t, ca = 1;scanf("%d", &t);
while(t--){
scanf("%d", &n);
memset(c1, 0, sizeof(c1));
memset(c2, 0, sizeof(c2));
int l, r, x, y, z, d;

tot = 0;
for(int i = 0; i < n; i++){
scanf("%d%d%d%d", &x, &y, &z, &d);
l = y-z+maxn, r = x+z+maxn;
ope[tot++] = l, ope[tot++] = r;
pp[i] = p(l, r, d);
}

sort(ope, ope+tot);
//tot = unique(ope, ope+tot)-ope;
for(int i = 0; i < n; i++){
int l = lower_bound(ope, ope+tot, pp[i].l)-ope+1;
int r = lower_bound(ope, ope+tot, pp[i].r)-ope+1;
int d = pp[i].d;
if(l <= r)
Add(l, r, (d == 1? c1 : c2));
}

for(int i = 1; i < (maxn<<2); i++)
c1[i] += c1[i-1], c2[i] += c2[i-1];

int ans = 0;
for(int i = (maxn<<2)-2; i > 0; i--){
c2[i] = max(c2[i], c2[i+1]);
ans = max(ans, c1[i]+c2[i]);
}
printf("Case #%d:\n%d\n", ca++, ans);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: