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个点 两个人轮流在任意两个点之间连一条线但是不能和已有的线相交,先围成一个凸多边形的获胜,先手赢还 ...
随机推荐
- hdu_1573_X问题 (分段之中国剩余
求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0], X mod a[1] = b[1], X mod a[2] = b[2], …, X mod a[i] = b[i], … ...
- Smartforms 设置纸张打印格式
在sap做一个打印报表,要先设置一个纸张打印格式,下面以工厂中常用来打印的针孔纸为例,在sap设置该纸张的打印格式,以用于报表: 1.运行事务代码SPAD:选择工具栏上的[完全管理]按钮——>选 ...
- 连接mysql 报错 Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
网上找不到 朋友说是因为非正常关机导致,mysql.server start 运行报错 ERROR! The server quit without updating PID file(): 解决办 ...
- nginx虚拟主机搭建
nginx [engine x]是 Igor Sysoev 编写的一个 HTTP 和反向代理服务器,另外它也可以 作为邮件代理服务器. 它已经在众多流量很大的俄罗斯网站上使用了很长时间,这些网站包括 ...
- JavaScript数组常用的方法
改变原数组: ※ push,pop,shif,unshift,sort,reverse ※ splice 不改变原数组: ※ concat,join→split,toString,slice push ...
- SSO 单点登录总结(PHP)
本篇文章根据个人理解的知识整理汇总,如有不足之处,请大家多多指正. 单点登录(SSO--Single Sign On)的应用是很普遍的,尤其在大型网站系统中,比如百度,登录百度账号和,再转到百度经验. ...
- php-安装与配置-未完待续2
一,准备工作 在入门指引中,我们已经知道PHP的3个应用领域,不同的场景,需要安装的东西是不同的.具体如下: 服务器端脚本,在通常情况下,需要三样东西:PHP 自身.一个 web 服务器和一个 web ...
- 裸机——I2C
网上搜了些资料,碍于智商和基础,看不懂, 只有将S5PV210 数据手册关于I2C的部分,翻译记录下,留到以后用. 1.OVERVIEW The S5PV210 RISC microprocessor ...
- HDU 3364 高斯消元
Lanterns Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Su ...
- POJ 3608 凸包间最短距离(旋转卡壳)
Bridge Across Islands Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11539 Accepted: ...