CodeForces - 255D Mr. Bender and Square 二分 + 边界判断

本文探讨了一个数字表格中点亮单元格的策略,以满足特定数量的点亮条件。通过二分搜索和数学公式计算不同时间点点亮的单元格总数,解决了一个有趣的算法问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.

We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on.

For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1).

In how many seconds will Mr. Bender get happy?

Input

The first line contains four space-separated integers n, x, y, c (1 ≤ n, c ≤ 109; 1 ≤ x, y ≤ nc ≤ n2).

Output

In a single line print a single integer — the answer to the problem.

Examples

Input

6 4 3 1

Output

0

Input

9 3 8 10

Output

2

Note

Initially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. .

题解:找一个最小符合条件的,我们可以二分枚举答案来做,然后我们怎么求时间为 t 时细胞的总数呢  假设边界是无穷大的

总数为: t * 4 + t * (t - 1) / 2  * 4   +  1  先是4个方向 然后加上 任意两方向对应的直角依次叠加 

然后就是减去超出边界的 假设到 某一边的距离为 x  超出就为 2 * (t - 1 - x) * (t - 1 - x + 1) / 2  +  t -  x 这个方向两边都超出了

再然后就是超出的部分有相交的部分 就是角上  假设点到达该角对应两边的距离为 x y 那超出部分为 (t-1-x-y)(t-1-x-y+1)/2

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll n,x,y,m;
ll cul(ll p)
{
	if(p<=0) return 0;
	return (p+1)*p/2;
}
int judge(ll p)
{
	ll a=x-1,b=y-1,c=n-x,d=n-y;
	ll ans=min(p,a)+min(p,b)+min(p,c)+min(p,d)+1;
	p--;
	ans+=cul(p)*4-2*cul(p-a)-2*cul(p-b)-2*cul(p-c)-2*cul(p-d);
	ans+=cul(p-a-b)+cul(p-b-c)+cul(p-c-d)+cul(p-d-a);
	return ans>=m;
}
int main()
{
	scanf("%lld%lld%lld%lld",&n,&x,&y,&m);
	ll l=0,r=1e9,ans=0;
//	cout<<judge(2)<<endl;
	while(l<=r)
	{
		ll mid=(r+l)>>1;
		if(judge(mid))
		{
			ans=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
} 

 

【基于QT的调色板】是一个使用Qt框架开发的色彩选择工具,类似于Windows操作系统中常见的颜色选取器。Qt是一个跨平台的应用程序开发框架,广泛应用于桌面、移动和嵌入式设备,支持C++和QML语言。这个调色板功能提供了横竖两种渐变模式,用户可以方便地选取所需的颜色值。 在Qt中,调色板(QPalette)是一个关键的类,用于管理应用程序的视觉样式。QPalette包含了一系列的颜色角色,如背景色、前景色、文本色、高亮色等,这些颜色可以根据用户的系统设置或应用程序的需求进行定制。通过自定义QPalette,开发者可以创建具有独特视觉风格的应用程序。 该调色板功能可能使用了QColorDialog,这是一个标准的Qt对话框,允许用户选择颜色。QColorDialog提供了一种简单的方式来获取用户的颜色选择,通常包括一个调色板界面,用户可以通过滑动或点击来选择RGB、HSV或其他色彩模型中的颜色。 横渐变取色可能通过QGradient实现,QGradient允许开发者创建线性或径向的色彩渐变。线性渐变(QLinearGradient)沿直线从一个点到另一个点过渡颜色,而径向渐变(QRadialGradient)则以圆心为中心向外扩散颜色。在调色板中,用户可能可以通过滑动条或鼠标拖动来改变渐变的位置,从而选取不同位置的颜色。 竖渐变取色则可能是通过调整QGradient的方向来实现的,将原本水平的渐变方向改为垂直。这种设计可以提供另一种方式来探索颜色空间,使得选取颜色更为直观和便捷。 在【colorpanelhsb】这个文件名中,我们可以推测这是与HSB(色相、饱和度、亮度)色彩模型相关的代码或资源。HSB模型是另一种常见且直观的颜色表示方式,与RGB或CMYK模型不同,它以人的感知为基础,更容易理解。在这个调色板中,用户可能可以通过调整H、S、B三个参数来选取所需的颜色。 基于QT的调色板是一个利用Qt框架和其提供的色彩管理工具,如QPalette、QColorDialog、QGradient等,构建的交互式颜色选择组件。它不仅提供了横竖渐变的色彩选取方式,还可能支持HSB色彩模型,使得用户在开发图形用户界面时能更加灵活和精准地控制色彩。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值