百度之星复赛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 —— 山谷的,像下面这张图. 为了形成山谷,首先要将一个图的顶点标记为高点或者低点.标 ...
随机推荐
- 怎样用PHP制作验证码呢?
生成验证码无非就那么几个步骤,首先是获取一个随机字符串,然后创建一个布画,将生成的字符串写到布画上,我们还可以在布画上画线画雪花,现在帖一段生成验证码的代码. 源代码: <?phpsession ...
- android中文件操作的四种枚举
1.MODE_PRIVATE:默认操作模式,代表该文件是私有数据,只能被应用自身访问,在该模式下,写入的的内容会覆盖原文件中的内容. 2.MODE_APPEND:该模式会检查文件是否存在,存在就往文件 ...
- HDU 4707:Pet
Pet Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- YTU 2295: KMP模式匹配 一(串)
2295: KMP模式匹配 一(串) 时间限制: 1 Sec 内存限制: 128 MB 提交: 32 解决: 22 题目描述 求子串的next值,用next数组存放,全部输出 输入 输入一个字符串 ...
- 哈希-Snowflake Snow Snowflakes 分类: POJ 哈希 2015-08-06 20:53 2人阅读 评论(0) 收藏
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 34762 Accepted: ...
- windows下TCP服务器和客户端的实现
服务器 1.初始化 WSAStartup(..) 2.创建Socket s = Socket ( .. ) 3.绑定端口 ret = bind ( ... ) 4.监听 ret = ...
- Entity Framework 第五篇 状态跟踪
本人建议尽量使用EntityState来表名Entry的状态,而不要使用Configuration.AutoDetectChangesEnabled自动状态跟踪,为什么我这么建议呢?他们到底有什么异同 ...
- Android开发中,那些让您觉得相见恨晚的方法、类或接口
Android开发中,那些让你觉得相见恨晚的方法.类或接口本篇文章内容提取自知乎Android开发中,有哪些让你觉得相见恨晚的方法.类或接口?,其实有一部是JAVA的,但是在android开发中也算常 ...
- uTenux\AT91SAM3S4C开发套件———硬件电路介绍
无论写什么嵌入式软件,我们都应该首先对硬件有所了解,这样更有助于我们写出高效精简的程序代码.本次活动我们使用的硬件平台是有悠龙公司提供的uTenux\AT91SAM3S4C开发套件,在悠龙公司的主页可 ...
- UE4高级功能--初探超大无缝地图的实现LevelStream
转自:http://blog.csdn.net/u011707076/article/details/44903223 LevelStream 实现超大无缝地图--官方文档学习 The Level S ...