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个点 两个人轮流在任意两个点之间连一条线但是不能和已有的线相交,先围成一个凸多边形的获胜,先手赢还 ...
随机推荐
- SpringMVC系列一
首先介绍一下SpringMVC的执行流程:如图 1.用户在客户端发送请求,经过前端控制器DispatcherServlet,请求处理器处理,返回ModelAndView返回结果到前端控制器: 2.前端 ...
- zeppelin ERROR总结
ERROR [2017-03-23 20:01:50,799] ({qtp331657670-221} NotebookServer.java[onMessage]:221) - Can't hand ...
- 自定义扩展Compare比较方法
public static int Compare<T, V>(this T x, T y, Func<T, V> func) { return Comparer<V&g ...
- Lucene实战
导包
- centos7重启apache、nginx、mysql、php-fpm命令
apache启动systemctl start httpd停止systemctl stop httpd重启systemctl restart httpd mysql启动systemctl start ...
- 呕心沥血写的python猜数字
#猜数字 import random num_rd=random.randint(0,100) count=1 while 1<=count<=10: num_ip=input('请输入0 ...
- python学习之变量类型
变量: 变量是保存在内存中的值,根据变量类型开辟不同的内存空间且只允许符合该数据类型的数据才可以被存储在该内存空间中 变量赋值: 在Python中定义变量时,无需像其他语言一样需要声明数据类型.每个变 ...
- POJ 2084 Catalan
Game of Connections Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 8772 Accepted: 43 ...
- POJ:2100-Graveyard Design(尺取)
Graveyard Design Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 8504 Accepted: 2126 Cas ...
- JAVA-数组或集合
哈哈,今天我们来讲解一下有关于一些数组 或者是集合的知识点 1.ArrayList,LinkedList,Vector的区别 ArrayList,LinkedList,Vector都是实现List接口 ...