百度之星复赛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 —— 山谷的,像下面这张图. 为了形成山谷,首先要将一个图的顶点标记为高点或者低点.标 ...
随机推荐
- 3、JavaScript
1. JavaScript简介 1.1. JavaScript由来 Netscape 发明了 JavaScript JavaScript由Netscape 在1995年发明.早期的主要目的是处理 ...
- 《QT Creator快速入门》
ui中的类,这样使用无法通过调试: Ui::Dialog ui(&w); w.show(); 而需要改成: Ui::Dialog ui; ui.setupUi(&w); w.show( ...
- Java BIO、NIO、AIO-------转载
先来个例子理解一下概念,以银行取款为例: 同步 : 自己亲自出马持银行卡到银行取钱(使用同步IO时,Java自己处理IO读写). 异步 : 委托一小弟拿银行卡到银行取钱,然后给你(使用异步IO时,Ja ...
- poj3342 Party at Hali-Bula
树形dp题,状态转移方程应该很好推,但一定要细心. http://poj.org/problem?id=3342 #include <cstdio> #include <cstrin ...
- 栈——PowerShell版
上一篇讲过队列(queue),队列就像是居民楼里的垃圾管道,从楼道的垃圾管道的入口处将垃圾扔进去,清洁工会从一楼垃圾管道的出口处将垃圾拿走.每一层的垃圾通道入口与一楼的垃圾管道出口之间都形成了一个队列 ...
- java提高篇---Vector
对于List接口这里还介绍一个它的实现类Vector,Vector 类可以实现可增长的对象数组. 一.Vector简介 Vector可以实现可增长的对象数组.与数组一样,它包含可以使用整数索引进行访问 ...
- 2016年10月31日 星期一 --出埃及记 Exodus 19:16
2016年10月31日 星期一 --出埃及记 Exodus 19:16 On the morning of the third day there was thunder and lightning, ...
- Java爬虫工程师技能列表
以下仅仅是自己一些粗浅认识.欢迎补充指正.欢迎进群交流! 掌握一半便能够熟练的开发爬虫玩了.自己正在努力中... 一.技能列表 1.掌握java.尤其编程网络部分:李刚的java基础至少看了三遍以上: ...
- C#String详解
字符串:stringLength - 字符串的长度. TrimStart() 压缩空格即消除字符串开始空格TrimEnd() 消除结尾空格Trim() 同时消除开头和结尾空格.注:中间空格不消除,因为 ...
- ZOJ 2182 Cable TV Network(无向图点割-最大流)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2182 题意:给出一个无向图,问最少删掉多少个顶点之后图变得不连通 ...