百度之星复赛Astar Round3
拍照
树状数组(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;
//c1 向右开的船
int c1[maxn<<], c2[maxn<<];
int s1[maxn<<], s2[maxn<<]; int lowbit(int x){ return x&-x;}
void add(int x, int d, int* c){//c[x]++;
while(x <= (maxn<<)){
c[x] += d;
x += lowbit(x);
}
}
void Add(int l, int r, int* c){
add(l, , c);
add(r+, -, c);
}
int sum(int x, int* c){
int ret = ;
while(x > ){
ret += c[x];
x -= (x&-x);
}
return ret;
} 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 = ;scanf("%d", &t);
while(t--){
scanf("%d", &n);
memset(c1, , sizeof(c1));
memset(c2, , sizeof(c2));
int l, r, x, y, z, d; tot = ;
for(int i = ; 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 = ; i < n; i++){
int l = lower_bound(ope, ope+tot, pp[i].l)-ope+;
int r = lower_bound(ope, ope+tot, pp[i].r)-ope+;
int d = pp[i].d;
if(l <= r)
Add(l, r, (d == ? c1 : c2));
} for(int i = ; i < (maxn<<); i++)
s1[i] = sum(i, c1);
for(int i = ; i < (maxn<<); i++)
s2[i] = sum(i, c2); int ans = ;
for(int i = (maxn<<)-; i > ; i--){
s2[i] = max(s2[i], s2[i+]);
ans = max(ans, s1[i]+s2[i]);
}
printf("Case #%d:\n%d\n", ca++, ans);
}
return ;
}
更新:SB了,要树状数组干什么用。。反正是要求出 每个点 能看到的船只数,直接做一遍前缀和累加一下就可以了。。。树状数组都省了。
代码如下:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std; const int maxn =2e4;
int c1[maxn<<], c2[maxn<<]; void Add(int l, int r, int* c){
c[l]++, c[r+]--;
} 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 = ;scanf("%d", &t);
while(t--){
scanf("%d", &n);
memset(c1, , sizeof(c1));
memset(c2, , sizeof(c2));
int l, r, x, y, z, d; tot = ;
for(int i = ; 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 = ; i < n; i++){
int l = lower_bound(ope, ope+tot, pp[i].l)-ope+;
int r = lower_bound(ope, ope+tot, pp[i].r)-ope+;
int d = pp[i].d;
if(l <= r)
Add(l, r, (d == ? c1 : c2));
} for(int i = ; i < (maxn<<); i++)
c1[i] += c1[i-], c2[i] += c2[i-]; int ans = ;
for(int i = (maxn<<)-; i > ; i--){
c2[i] = max(c2[i], c2[i+]);
ans = max(ans, c1[i]+c2[i]);
}
printf("Case #%d:\n%d\n", ca++, ans);
}
return ;
}
百度之星复赛Astar Round3的更多相关文章
- 2016"百度之星" - 复赛(Astar Round3) 1003 拍照
拍照 思路:先静态,离线树状数组,分别统计每个点向左向右能看到的船的数量.再枚举整个区间求最大值. 应为人和船都是动态的,假设船往左走,处理每个点看到向左最大船的数量,满足动态条件.就是向左的船一开始 ...
- hdu5713 K个联通块[2016百度之星复赛B题]
dp 代码 #include<cstdio> ; ; int n,m,k,cnt[N]; ]; ][],i,j,l,a,b; int check(int x,int y) { int i; ...
- hdu5714 拍照[2016百度之星复赛C题]
由于船移动的速度都一样,那么对于往一个方向的船相对距离其实是不变的,我们可以把往一个方向移动的船都视作静止,并求出在哪些观测位置可以看到,很明显对于船[x,y,z],当x+z>=y-z的时候,可 ...
- hdu5715 XOR 游戏 [2016百度之星复赛D题]
比赛的时候没仔细想,赛后一想这题其实挺简单的,先求出序列的异或前缀和,然后将异或前缀和建出一颗trie树,然后我们可以二分答案,把问题变成判定性问题,判定是否存在一种方案,使得所有的分组的异或和都大 ...
- 最强密码 (百度之星复赛 T5)
题目大意: 给出一个字符串A,要求最短的字符串B,B不是A的子序列. 求最短长度 和 最短的字符串个数 |A|<=105. 题解: 1.比赛的时候没有想出来,时隔一个多月又看到了这道题,虽 ...
- 2016百度之星-初赛(Astar Round2A)AII X
Problem Description F(x,m) 代表一个全是由数字x组成的m位数字.请计算,以下式子是否成立: F(x,m) mod k ≡ c Input 第一行一个整数T,表示T组数据. 每 ...
- 百度之星复赛 1004 / hdu5715 二分dp+trie
XOR 游戏 Problem Description 众所周知,度度熊喜欢XOR运算[(XOR百科)](http://baike.baidu.com/view/674171.htm). 今天,它发 ...
- 2016"百度之星" - 初赛(Astar Round2B) 1006 中位数计数
思路:统计当前数左边比它小|大 i个人,相应右边就应该是比它大|小i个人 l数组表示左边i个人的方案 r表示右边i个人的方案 数组下标不可能是负数所以要加n //#pragma comment(lin ...
- 百度之星复赛T6&&hd6149 ——Valley Numer II
Problem Description 众所周知,度度熊非常喜欢图. 它最近发现了图中也是可以出现 valley —— 山谷的,像下面这张图. 为了形成山谷,首先要将一个图的顶点标记为高点或者低点.标 ...
随机推荐
- 微信开放平台API开发资料
微信大概两年前开启了微信公众平台的API供开发者使用,从账号登陆.消息发送.用户账号管理.公众号菜单.客服接口.微信商店接口.用户卡券接口 以及微信支付接口.可以说是全方面覆盖了电商所需要的要素,与阿 ...
- [HTML]HTML框架IFrame下利用JS在主页面和子页面间传值
今天写的程序涉及到JS框架传值的问题,这些是我找到的一些资料 下面主页面和子页面互相传值的DEMO 如果仅仅需要子页面触发主页面的函数 仅需 [ parent.window.你的函数 ] 就可以了 D ...
- 关于数据库表中的索引及索引列的CRUD
-- 查询一个数据库表中的索引及索引列use [RuPengWangDB]GOSELECT indexname = a.name , tablename = c. name , indexcolu ...
- android内存优化相关1
第一种策略,是释放显示相关的内存.这是我们针对系统APP采用的一种调优策略. 图形内容,俗称位图是非常占用内存的,针对位图,我们采用异步加载的方法,将位图内容信息和位图的状态信息分别进行存储,将内容信 ...
- js笔记----(运动)分享 隐藏/显示
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- 连接无线设备——与Wi-Fi直接连接
原文链接:http://developer.android.com/intl/zh-CN/training/connect-devices-wirelessly/wifi-direct.html 目录 ...
- Curling 2.0 分类: 搜索 2015-08-09 11:14 3人阅读 评论(0) 收藏
Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14289 Accepted: 5962 Descript ...
- SortedDictionary和SortedList
使用上两者的接口都类似字典,并且SortedList的比如Find,FindIndex,RemoveAll常用方法都没提供. 数据结构上二者差异比较大,SortedList查找数据极快,但添加新元素, ...
- web前端职业规划
关于一个WEB前端的职业规划,其实是有各种的答案,没有哪种答案是完全正确的,全凭自己的选择,只要是自己选定了, 坚持去认真走,就好.在这里,我只是简要说一下自己对于这块儿内容的理解.有一个观点想要分享 ...
- Codeforces Round #260 (Div. 2) C
Description Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. On ...