百度之星复赛Astar Round3
2016-05-29 17:06
246 查看
拍照
树状数组(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; int c1[maxn<<2], c2[maxn<<2]; void Add(int l, int r, int* c){ c[l]++, c[r+1]--; } 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 = 1;scanf("%d", &t); while(t--){ scanf("%d", &n); memset(c1, 0, sizeof(c1)); memset(c2, 0, sizeof(c2)); int l, r, x, y, z, d; tot = 0; for(int i = 0; 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 = 0; i < n; i++){ int l = lower_bound(ope, ope+tot, pp[i].l)-ope+1; int r = lower_bound(ope, ope+tot, pp[i].r)-ope+1; int d = pp[i].d; if(l <= r) Add(l, r, (d == 1? c1 : c2)); } for(int i = 1; i < (maxn<<2); i++) c1[i] += c1[i-1], c2[i] += c2[i-1]; int ans = 0; for(int i = (maxn<<2)-2; i > 0; i--){ c2[i] = max(c2[i], c2[i+1]); ans = max(ans, c1[i]+c2[i]); } printf("Case #%d:\n%d\n", ca++, ans); } return 0; }
View Code
相关文章推荐
- hdu 1796(容斥原理+状态压缩)
- eclipse4.3 安装tomcat8
- maven 代理
- Java基础-double的精度问题
- Network In Network学习笔记-ICLR 2014
- 二分查找算法实现
- mybatis 中resultType与resultMap区别
- Javascript:面试最容易被问到的的7个框架
- ldap基本命令
- ssh-keygen
- Centos sudo添加用户
- CodeForces 592B
- 忙忙忙
- Hibernate从入门到放弃(三)----持久化对象
- Lock接口(锁的实现)
- 2.5 UI组件-AdapterView及子类(疯狂android学习笔记)
- 安装虚拟机报错:Could not get vmci driver version: 参数错误. You have an incorrect version of driver "vmci.sys".
- ssh proxy配置
- maven 命令
- HDU 1075 What Are You Talking About (map 或者 字典树)