Bishops Alliance

新手避坑指南:用PIC16F15355开发板和MCC完成第一个UART通信项目 本文为新手提供了使用PIC16F15355开发板和MPLAB代码配置器(MCC)实现首个UART通信项目的完整指南。通过图形化配置系统时钟、UART参数并自动生成驱动代码,手把手教学如何避开常见陷阱,快速完成从环境搭建、代码编写到调试输出的全流程,助力开发者高效入门PIC单片机开发。 阅读详情

F. Bishops Alliance
time limit per test
9 seconds
memory limit per test
256 megabytes
input
bishops.in
output
standard output

Chessforces is coming into a great war. The Knights Alliance is aiming to attack the Bishops Alliance land, it is up to you to help bishops defending their homeland.

In order to defeat the attacking knights, bishops want to make their defense line as big as possible. Defense line is a set of bishops on the chessboard where each pair of bishops in this set satisfies OK relation. OK relation between bishop i and bishop j is satisfied if they are on the same diagonal and the number of squares on the diagonal path between i and j is at least equal to pi2 + pj2 + C, where pk is privacy distance for bishop k and it is given for each bishop on the board, C is a given constant. Note that the path between two bishops includes both bishops squares.

Given the coordinates of each bishop on the chessboard, help them to find the defense line with maximum number of bishops.

Input

First line contains number of test cases T. Each test case contains one line with (0 < n ≤ 105) size of the chessboard edge, (0 < m ≤ 105) number of bishops and the constant (0 ≤ C ≤ 105) then m line follows, the ith line of them contains three integers: (1 ≤ ri, ci, pi ≤ n) where (ri,ci) is row number and column number of the ith bishop and pi is the privacy of the ith bishop.

Output

Print a single integer, the size of the defense line with maximum number of bishops.

Example
input
1
8 5 2
7 7 1
4 4 1
3 5 1
2 6 2
4 8 1
output
2
Note

Large I/O files. Please consider using fast input/output methods.

First test case explanation, columns go from left to right and rows go up to bottom, bishops labeled with borders are included in the defense line.



先把每一对角线上的点都记录下来,然后可以把每个点看为一个线段区间,这个区间的范围也就是[ xi- ( pi*pi+c/2+0.5 )  ,  xi + ( pi*pi+c/2+0.5 ) ]  这样只要两个区间不相交,就可以保证满足“OK relation”

然后就是对于每条对角线贪心求最大不相交区间覆盖



调了半天看了题解才知道要“

input
bishops.in"。。。。。。。。。。freopen("bishops.in","r",stdin); 

并且大牛们用的区间都是[ xi- ( pi*pi)  ,  xi + ( pi*pi) ]  因为那些项都是常数,可以在贪心时判断条件稍微改一下

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<functional>
#include<vector>
using namespace std;
struct node
{
	int x;
	double p;
};
double c;
int cmp(node a,node b)
{
	double s1=a.p+c/2-0.5,s2=b.p+c/2-0.5;
	if(1.0*a.x-s1==1.0*b.x-s2)
	return a.x+s1<b.x+s2;
	return 1.0*a.x-s1<1.0*b.x-s2;
}

vector<node>w[200005],v[200005];
int main()
{
	freopen("bishops.in","r",stdin);  
	int T,t,n,m,i,ans,j,x,y;
	double p;
	node point;
	scanf("%d",&T);
	while(T--)
	{
		ans=0;
		scanf("%d %d %lf",&n,&m,&c);
		for(i=0;i<=2*n+1;i++)
		{
			w[i].clear();
			v[i].clear();
		}
		for(i=0;i<m;i++)
		{
			scanf("%d %d %lf",&x,&y,&p);
			p*=p;
			point.x=x;
			point.p=p;
			w[x-y+n].push_back(point);
			v[x+y-1].push_back(point);	
		}

		for(i=0;i<=2*n;i++)
		{
			sort(w[i].begin(),w[i].end(),cmp);
			int t=0;
			node po;
			double ri;
			for(j=0;j<w[i].size();j++)
			{
				po=w[i][j];
				double s=po.p+c*1.0/2-0.5;
				if(j==0)
				{
					t=1;
					ri=po.x+s;
					continue;
				}
				if(ri<=1.0*po.x-s)
				{
					t++;
					ri=po.x+s;
				}
				else
				{
					ri=min(ri,po.x+s);
				}	
			}
			ans=max(ans,t);
		}
		//其实完全可以用三维vector嵌套一层循环,代码比较简练
		for(i=0;i<=2*n;i++)
		{
			sort(v[i].begin(),v[i].end(),cmp);
			int t=0;
			node po;
			double ri;
			for(j=0;j<v[i].size();j++)
			{
				po=v[i][j];
				double s=po.p+c*1.0/2-0.5;
				if(j==0)
				{
					t=1;
					ri=po.x+s;
					continue;
				}
				if(ri<=1.0*po.x-s)
				{
					t++;
					ri=po.x+s;
				}
				else
				{
					ri=min(ri,po.x+s);
				}	
			}
			ans=max(ans,t);
		}
		
		printf("%d\n",ans);
	}
	return 0;
}



基于Python的智能动漫更新监控爬虫系统:从原理到实战 本文详细介绍了如何使用Python构建一个智能化的动漫更新监控系统,涵盖从基础爬虫到高级自动化监控的全套解决方案。文章将深入探讨最新的网络爬虫技术,包括异步请求、反反爬策略、智能解析算法等,并提供完整的代码实现和性能优化方案。通过本系统,用户可以实时获取多个动漫平台的更新信息,并通过多种渠道接收通知。关键词:Python爬虫、动漫监控、自动化通知、异步爬虫、反反爬策略。 阅读详情

相关推荐

Mellanox ASAP2技术揭秘:如何通过硬件卸载提升OVS性能?

本文深入解析Mellanox ASAP2技术如何通过硬件卸载显著提升Open vSwitch(OVS)性能。通过将数据平面操作转移到ConnectX智能网卡处理,ASAP2实现了10倍吞吐量提升和90%延迟降低,同时大幅减少CPU占用。文章包含技术原理剖析、实战配置指南及性能对比数据,为网络虚拟化优化提供关键解决方案。

weixin_30335575的博客 379

GYM 101147 F.Bishops Alliance(dp+BIT)

Description 一个棋盘,上面有一些棋子,第i个棋子有一个p[i]值,现在要选择在同一条对角线上的某些棋子,使得对任意两个棋子i和j,i到j之间所隔格子数不小于pi^2+pj^2+c,其中c是一给定常数,问最多可以选多少个棋子 Input 第一行一整数T表示用例组数,每组用例首先输入三个整数n,m,c分别表示棋盘规格,棋子数量和常数c,之后m行每行三个整数xi,yi,pi表示第i个棋子

ZSQ 565

保姆级教程:用Vue3+Element Plus快速搭建Flowable流程定义管理后台界面

本文提供了一份详细的Vue3+Element Plus教程,指导开发者快速搭建Flowable流程定义管理后台界面。从项目初始化、核心页面设计到响应式数据处理,全面覆盖前端开发关键步骤,帮助提升企业级应用开发效率。

weixin_42662293的博客 488

Bishops Alliance Gym - 101147F

https://cn.vjudge.net/problem/Gym-101147F i-j>=pi^2+pj^2+C => i-pi^2>=j+pj^2+C-1; 最长上升子序列,树状数组维护; #include <iostream> #include <cstring> #include <queue> #include...

newhonor 225

【数据集6】全球人工不透水面积GAIA(清华数据)

全球人工不透水面GAIA简介及其应用

WW、forever的博客 3823

如何用 Claude Code 做代码重构,而不是重写

摘要: 在使用Claude Code进行代码优化时,AI容易“重写”而非“重构”,导致改动过大、review困难。本文提出3个关键约束方法:1)限制修改范围(如仅修改指定函数);2)明确不改变代码行为;3)要求最小必要修改。通过分步骤重构、先获取重构建议再修改、使用标准模板(保持函数签名/输入输出/结构不变)等方式,可使AI输出更符合工程需求的小范围安全重构。对于彻底混乱的代码,才建议直接重写。核心在于通过提示词精准约束AI的修改行为,将其转化为高效的代码重构助手。

sg_knight的专栏 987

Gym 101147F Bishops Alliance 题解

Gym 101147F题解

DarkoDu的博客 488

15、虚拟环境中的数据保护与恢复方案解析

本文深入解析了虚拟环境中两种重要的数据保护与恢复解决方案:RecoverPoint for Virtual Machines(RP4VM)在VxRail上的设计,以及Veeam Backup & Replication(VBR)与VxRail的集成方案。文章详细介绍了RP4VM的网络布局、故障转移场景及其相关问题,以及VBR的架构设计、备份与复制流程、许可证选项及其多平台支持特性。此外,还探讨了RP4VM与VBR结合使用的综合解决方案,以及未来数据保护领域的发展趋势,如智能化管理、云原生集成和零信任架构,为

t4y5u6i7o的博客 98

gym101147 Bishops Alliance

#include using namespace std; typedef long long ll; const int maxn = 100010; struct node{ int x;shuzhuang ll p; node(int x,ll p):x(x),p(p){} node(){} bool operator<(const node

Green_Days 552

【MATLAB代码】蚁群算法(Ant Colony Optimization, ACO)路径规划(避障)仿真程序,订阅专栏后可直接查看完整源代码

基于蚁群算法的路径规划系统。可自定义起点、终点和障碍物地图,系统通过蚁群算法自动计算最优路径,并输出路径坐标、障碍物地图和收敛曲线。完整MATLAB源代码直接运行。适用于复杂障碍环境下的路径优化问题。

985工科博士毕业,专攻定位、导航和滤波等算法研究。从业10年,主要使用MATLAB 3100

手把手教你RK3568 MIPI屏驱动适配,纯干货!

RK3568 作为一款高性能的多媒体处理器,在嵌入式领域中备受瞩目。它采用了先进的 22nm 制程工艺,搭载四核 Cortex-A55 处理器,这种架构为芯片提供了高效的功耗比,使其在运行各种复杂任务时,既能保证性能,又能有效控制功耗。在实际应用中,无论是多任务处理还是运行大型应用程序,RK3568 都能凭借其四核 Cortex-A55 处理器,实现流畅的操作体验,满足智能设备对高性能和低功耗的需求。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 4081

CodeForces Gym101147F Bishops Alliance

2016-2017 ACM-ICPC, Egyptian Collegiate Programming Contest (ECPC 16)

Tooc0ld 294

Android Camera驱动开发工程师面试指南:技术深度与实战准备

摘要:上海移远通信招聘Android Camera驱动开发工程师,主要负责Camera传感器驱动开发维护、高通/展锐平台底层开发及技术预研。岗位要求1年以上嵌入式开发经验,精通Camera传感器驱动调试,熟悉高通平台Camera架构及Android HAL框架。具备HAL开发、算法集成或车载/支付行业经验者优先。工作内容以Driver/HAL开发为主,需具备硬件接口评估能力。该职位接受Linux/单片机背景人员转型。

郑伟强dev的专栏 287

Gym 101147F Bishops Alliance (树状数组+DP)

题目链接:http://codeforces.com/gym/101147/problem/F #include&lt;bits/stdc++.h&gt; using namespace std; #define debug puts("YES"); #define rep(x,y,z) for(int (x)=(y);(x)&lt;(z);(x)++) #define ll long lon...

满月照亮的路 231

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Bishops Alliance—— 最大上升子序列

原题链接:http://codeforces.com/gym/101147/problem/F 题意:n*n的棋盘,给m个主教的坐标及其私有距离p,以及常数C,求位于同一对角线上满足条件:dist(i, j) >= p[i]^2 + p[j]^2 + C 的主教集合的元素个数最大值。 解题思路: 上述条件可以等价为:   d(j) - d(i) +1 >= p[i...

weixin_30493401的博客 141

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

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...

weixin_30312557的博客 148

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Codeforces Round #382 (Div. 2)A到D题 A. Ostap and //B. Urbanization//C. Tennis Championship//D. Taxes

A. Ostap and Grasshopper time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output On the way to Rio de Janeiro Ostap

jerans的博客 1289

Gym - 101128C Canvas Painting 逆向思维

https://odzkskevi.qnssl.com/3699857ff0a17d77d1099699cdf4da13?v=1490503337 刚开始读错题意,以为是不变序列,就想着区间dp但数据量肯定会t,,,没想到什么优化方法就放下了,后来队员发现序列是可变的。。。。任意的。。。。。 想着先排序在布拉布拉布拉,一直都没有逆向思维想到哈夫曼。只怪数据结构没认真听啊。。。。 想到哈夫

jerans的博客 947

CodeForces - 361D Levko and Array二分加dp

D. Levko and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Levko has an array that consists of inte

jerans的博客 840

Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C Fountains 乱搞

C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Arkady plays Gardenscapes a lot. Arkady wants

jerans的博客 811

codeforces 8VC Venture Cup 2017 - Elimination Round D PolandBall and Polygon

D. PolandBall and Polygon time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output PolandBall has such a convex poly

jerans的博客 727

B. The Meeting Place Cannot Be Changed

B. The Meeting Place Cannot Be Changed time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standard output The main road in Byt

jerans的博客 697

Codeforces Round #380 (Div. 2,Based on Technocup 2017 - Elimination Round 2)C - Road to Cine//

C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya is currently at a car rental service

jerans的博客 685

Beautiful numbers CodeForces - 55D 数位dp

D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Volodya is an odd boy and his taste is

jerans的博客 677

Codeforces Round #423 (Div. 2) C. String Reconstruction思维 D. High Load 构造

C:http://codeforces.com/contest/828/problem/C 题意:有一个字符串,你知道他的一些子串所在的位置,求符合条件的字典序最小的原串 因为已知的数据较大,还存在较多重复的部分,直接暴力不可行 可以记录原串每个位置的下一个没确定出来的字符的位置(记住next【i】),优化后可以过,时间较长 #include #define eps 1e-9 #defin

jerans的博客 672

Codeforces Round #410 (Div. 2) C. Mike and gcd problem 贪心

C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a sequence A = [a1, a2, ..

jerans的博客 664
上一篇: 100篇!!
下一篇: Codeforces Round #403 (Div. 2) C. Andryusha and Colored Balloons dfs(树)
jerans
博客等级 码龄10年 54粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值