百度之星复赛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 —— 山谷的,像下面这张图. 为了形成山谷,首先要将一个图的顶点标记为高点或者低点.标 ... 
随机推荐
- linux命令:du 命令
			Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的. 1.命令格式: du [选项][文件] 2.命令功能 ... 
- Asp.net Vnext  ModelBinding
			Model Binding 本文已经同步到<Asp.net Vnext 系列教程 >中] Model binding(绑定)简单来说就是通过遍历ValueProvider(值提供者)获取的 ... 
- js中RHS与LHS区别
			为什么区分RHS与LHS是一件重要的事情? 因为在变量没有声明(在任何作用域都找不到该变量的情况下),这两种查询的行为是不一样的. function foo (a) { console.log(a + ... 
- gets()和getchar()还有getch()的区别
			getch()和getchar()区别:1.getch(): 所在头文件:conio.h 函数用途:从控制台读取一个字符,但不显示在屏幕上例如: char ch;或int ch: getch();或c ... 
- IE6下 input 背景图滚动问题及标签规范
			ie6 背景图滚动问题: <title>ie6下input背景图滚动问题</title> <style> .box{ height:20px; width:300p ... 
- 山东理工大学第七届ACM校赛-经济节约                                                       分类:            比赛             2015-06-26 10:34    19人阅读    评论(0)    收藏
			经济节约 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 由于经济紧张,某国国王决定减少一部分多余的士兵,这些士兵在边界都有各自的 ... 
- 移动平台前端开发之WebApp代码技巧
			1.首先我们来看看webkit内核中的一些私有的meta标签,这些meta标签在开发webapp时起到非常重要的作用 <meta content="width=device-width ... 
- 怎样解决:未找到路径“……”的控制器或该控制器未实现 IController?
			就是要加上new{area=""},比如下面的: @{Html.RenderAction("Cartsummary","ShoppingCart&qu ... 
- PHP去除连续空格
			<?php $note = strip_tags($value['Content']); $note = trim($note); $note = str_replace(" &quo ... 
- Struts2的标签库(五)——表单标签
			Struts2的标签库(五) --表单标签 几个特殊的表单标签的使用: 1.checkboxlist标签 该标签用于创建多个复选框,用于同时生成多个<input type="check ... 
