拍照

树状数组(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的更多相关文章

  1. 2016"百度之星" - 复赛(Astar Round3) 1003 拍照

    拍照 思路:先静态,离线树状数组,分别统计每个点向左向右能看到的船的数量.再枚举整个区间求最大值. 应为人和船都是动态的,假设船往左走,处理每个点看到向左最大船的数量,满足动态条件.就是向左的船一开始 ...

  2. 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; ...

  3. hdu5714 拍照[2016百度之星复赛C题]

    由于船移动的速度都一样,那么对于往一个方向的船相对距离其实是不变的,我们可以把往一个方向移动的船都视作静止,并求出在哪些观测位置可以看到,很明显对于船[x,y,z],当x+z>=y-z的时候,可 ...

  4. hdu5715 XOR 游戏 [2016百度之星复赛D题]

     比赛的时候没仔细想,赛后一想这题其实挺简单的,先求出序列的异或前缀和,然后将异或前缀和建出一颗trie树,然后我们可以二分答案,把问题变成判定性问题,判定是否存在一种方案,使得所有的分组的异或和都大 ...

  5. 最强密码 (百度之星复赛 T5)

    题目大意: 给出一个字符串A,要求最短的字符串B,B不是A的子序列. 求最短长度 和 最短的字符串个数    |A|<=105. 题解: 1.比赛的时候没有想出来,时隔一个多月又看到了这道题,虽 ...

  6. 2016百度之星-初赛(Astar Round2A)AII X

    Problem Description F(x,m) 代表一个全是由数字x组成的m位数字.请计算,以下式子是否成立: F(x,m) mod k ≡ c Input 第一行一个整数T,表示T组数据. 每 ...

  7. 百度之星复赛 1004 / hdu5715 二分dp+trie

    XOR 游戏 Problem Description   众所周知,度度熊喜欢XOR运算[(XOR百科)](http://baike.baidu.com/view/674171.htm). 今天,它发 ...

  8. 2016"百度之星" - 初赛(Astar Round2B) 1006 中位数计数

    思路:统计当前数左边比它小|大 i个人,相应右边就应该是比它大|小i个人 l数组表示左边i个人的方案 r表示右边i个人的方案 数组下标不可能是负数所以要加n //#pragma comment(lin ...

  9. 百度之星复赛T6&&hd6149 ——Valley Numer II

    Problem Description 众所周知,度度熊非常喜欢图. 它最近发现了图中也是可以出现 valley —— 山谷的,像下面这张图. 为了形成山谷,首先要将一个图的顶点标记为高点或者低点.标 ...

随机推荐

  1. Sqoop安装及操作

    一.集群环境: Hostname IP Hadoop版本 Hadoop 功能 系统 node1 192.168.1.151 0.20.0 namenode hive+sqoop rhel5.4X86 ...

  2. PHP高级架构技术年度大盘点

    2015年1月的最后一个周末,上海的冬季虽不如北方的雪窖冰天,但腊月的寒风也足以让人猫 在家中不愿出门.可是,在华美达酒店的一个会议室中,却人声鼎沸.春意融融,第三期商派技术沙龙正在火热进行,本期沙龙 ...

  3. 完整学习git四git对象

    1查看git对象 git cat-file 实践 git head到底指向的是什么 ➜ gittest git:(master) find .git -name HEAD -o -name maste ...

  4. javaScript数组循环删除

    遍历数组循环的时候,限定条件不要写arr.length,因为数组的长度会随着删除元素的同时减小. 例如,一个原本长度为10的数组,如果采用 for(var i = 0; i< arr.lengt ...

  5. 将turnserver设定成开机启动

    1.创建一个文件,在目录/etc/init/下面 #sudo vim /etc/init/turnserver.conf 2.添加如下内容 description "turn server& ...

  6. Find The Multiple 分类: 搜索 POJ 2015-08-09 15:19 3人阅读 评论(0) 收藏

    Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21851 Accepted: 8984 Sp ...

  7. 一些常用的SQL查询语句

    学习网站:http://www.w3cschool.cc/sql/sql-tutorial.html 一:查询所有表的属性 SELECT 'ALTER TABLE '+ CASE WHEN O.sch ...

  8. MySql5.7-多源复制(多主单从)

    1.1.主库配置 my.cnf   #确保唯一 server-id=1 #作为Master要开启binlog log-bin=mysql-bin #binlog format有三种形式:Stateme ...

  9. 开发与测试整体过程中的Git分支merge流程

    开发与测试整体过程中的Git分支merge流程 Git分支merge之开发流程 首先在Gitlab上有个仓库存储着原始的项目代码,其中包含一个叫master的分支.然后可能按功能进行分配,由不同的开发 ...

  10. [Django_1_0]初次见面

    Django 初次见面 文章将写安装和第一次使用时候的操作.文章是照着文档做的,但是以后的内容会有不一样. 安装 pip install django 我这里是使用python3的,也可以使用 pip ...