GYM - 101147 F.Bishops Alliance
题意:
一个n*n的棋盘,有m个主教。每个主教都有自己的权值p。给出一个值C,在棋盘中找到一个最大点集。这个点集中的点在同一条对角线上且对于点集中任意两点(i,j),i和j之间的主教数(包括i,j)不小于pi^2+pj^2+C。
题解:
对角线有2个方向,每个方向有2*n-1条对角线。一共时4*n-2条。每个点都在2条对角线上。
对于在同一对角线上的点(i,j)若满足i-j+1>=pi^2+pj^2+C即-j-pj^2>=pi^2+C-i-1(i>j)即可。
那么将同一对角线上的点按x坐标排序。将每个点的信息整合到一起离散化,最后用树状数组维护每个点前面满足-j-pj^2>=pi^2+C-i-1的最大值。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
const int maxn = 1e5+;
int t;
int n, m;
ll c;
int u, v;
ll p;
int cnt;
int ans;
ll _sort[maxn<<];
int tree[maxn<<];
struct node {
int x;
ll val;
node(int a, ll b) {
x = a; val = b;
}
};
vector<P> bs[][maxn<<];
void update(int x, int val) {
while(x <= cnt) {
tree[x] = max(tree[x], val);
x += x&(-x);
}
}
int sum(int x) {
int res = ;
while(x > ) {
res = max(res, tree[x]);
x -= x&(-x);
}
return res;
}
int main() {
freopen("bishops.in","r",stdin);
scanf("%d", &t);
while(t--) {
ans = ;
scanf("%d%d%lld", &n, &m, &c);
for(int i = ; i < ; i++)
for(int j = ; j < *n; j++) bs[i][j].clear();
while(m--) {
scanf("%d%d%lld", &u, &v, &p);
p *= p;
bs[][u+v-].push_back(P(u, p));
bs[][u-v+n].push_back(P(u, p));
}
for(int i = ; i < ; i++)
for(int j = ; j < *n; j++) sort(bs[i][j].begin(), bs[i][j].end()); for(int i = ; i < ; i++)
for(int j = ; j < *n; j++) {
int len = bs[i][j].size();
cnt = ;
for(int k = ; k < len; k++) {
int x = bs[i][j][k].first;
ll p = bs[i][j][k].second;
_sort[cnt++] = -p-x;
_sort[cnt++] = p+c-x-;
}
sort(_sort, _sort+cnt);
cnt = unique(_sort, _sort+cnt)-_sort;
for(int k = ; k <= cnt; k++) tree[k] = ;
for(int k = ; k < len; k++) {
int x = bs[i][j][k].first;
ll p = bs[i][j][k].second;
int id = cnt-(lower_bound(_sort, _sort+cnt, p+c-x-)-_sort);
int tmp = sum(id);
ans = max(ans, tmp+);
id = cnt-(lower_bound(_sort, _sort+cnt, -p-x)-_sort);
update(id, tmp+);
}
}
printf("%d\n", ans);
}
}
GYM - 101147 F.Bishops Alliance的更多相关文章
- Bishops Alliance—— 最大上升子序列
原题链接:http://codeforces.com/gym/101147/problem/F 题意:n*n的棋盘,给m个主教的坐标及其私有距离p,以及常数C,求位于同一对角线上满足条件:dist(i ...
- Gym 100637F F. The Pool for Lucky Ones
F. The Pool for Lucky Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- codeforces Gym 100187F F - Doomsday 区间覆盖贪心
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...
- Codeforces gym 100685 F. Flood bfs
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Desc ...
- Gym 100637F F. The Pool for Lucky Ones 暴力
F. The Pool for Lucky Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- Codeforces Gym 100513F F. Ilya Muromets 线段树
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...
- Codeforces Gym 100513F F. Ilya Muromets 水题
F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...
- Gym - 100283F F. Bakkar In The Army —— 二分
题目链接:http://codeforces.com/gym/100283/problem/F F. Bakkar In The Army time limit per test 2 seconds ...
- 2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2) GYM 102058 F SG函数
http://codeforces.com/gym/102058/problem/F 题意:平面上n个点 两个人轮流在任意两个点之间连一条线但是不能和已有的线相交,先围成一个凸多边形的获胜,先手赢还 ...
随机推荐
- Anaconda下安装 TensorFlow 和 keras 以及连接pycharm
首先在官网下载Anaconda https://www.anaconda.com/download/ 安装时注意 勾选第一个,增加环境变量 安装好后再windows界面打开Anaconda Promp ...
- mongodb多个查询语句
db.getCollection('costitems').find({"created":{"$gte":ISODate("2019-01-02T0 ...
- GNU汇编 伪指令
伪指令 本身并没有所对应的机器码 它只是在编译的时候起作用,或者转换为其他的实际指令来运行 global ascii byte word data equ align @ 下面的例子是在数据段存放数据 ...
- 在github上查找star最多的项目
如何在github上查找star最多的项目 在search中输入stars:>1 就可以查找所有有star的项目,然后右上角根据自己的需要筛选 当我输入stars:>10000的时候,就会 ...
- Python面向对象--高级(一)
## 属性的类型 - 属性可分为类属性和实例属性 - 实例属性可以通过在类中使用self定义,或者直接在类外部使用实例变量定义 class Person(object): def __init__(s ...
- js如何获得系统时间年月日时分秒
javascript 自带有个对象(构造函数),Date().下面是代码: 回答一: var now = new Date(); var nowTime = now.toLocaleString() ...
- Codeforces Round #460 (Div. 2).E 费马小定理+中国剩余定理
E. Congruence Equation time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
- 开放定址法——线性探测(Linear Probing)
之前我们所采用的那种方法,也被称之为封闭定址法.每个桶单元里存的都是那些与这个桶地址比如K相冲突的词条.也就是说每个词条应该属于哪个桶所对应的列表,都是在事先已经注定的.经过一个确定的哈希函数,这些绿 ...
- 分离链接法(Separate Chaining)
之前我们说过,对于需要动态维护的散列表 冲突是不可避免的,无论你的散列函数设计的有多么精妙.因此我们解决的重要问题就是:一旦发生冲突,我们该如何加以排解? 我们在这里讨论最常见的两种方法:分离链接法和 ...
- 使用Windows Live Writer写文章时不要用360清除垃圾
ref:http://www.zhengsiwei.com/write-an-article-to-use-windows-live-writer-dont-use-360-to-remove-rub ...