跳到正文

个人记录

5.1模拟赛

hhhh2971约 5 分钟
原文
文章信息与版本

文章信息

发布
2026年5月1日
收录
2026年5月3日
更新
2026年11月14日
篇幅
约 5 分钟

版本

  1. v2当前
  2. v1

1.期望得分

100+100+40+10=250100+100+40+10=250

2.实际得分

100+100+40+10=250100+100+40+10=250

3.失分原因

无

4.T2题解

题目传送门

我们观察题目可以发现,这道题满足二分的性质,因为一定存在一个答案,使得比他小的所有数都满足题目,所有比他大的数都不满足题目。

那么,checkcheck函数该怎么写呢?我们可以先找出所有满足长度为midmid的行和列,然后,如果行数或列数≥2\ge 2,那一定是可行的。否则,如果行数或列数有一个没有,那也一定不行。然后,就是判断一个行和一个列的情况。首先,如果这两个不相交,那也一定可以。如果两个相交,我们便要判断这两个的相交情况,看看相交后这两个被分成的四段有没有一段横的和一段竖的都满足长度≥mid\ge mid。

这是我的AC代码:

C++
#include<bits/stdc++.h>
using namespace std;

struct Node
{
	int st,en,wei;
};

char c[1505][1505];

Node hang[4000005],lie[4000005];
int n;

bool chk(int mid)
{
	int cnth=0;
	for (int i=1;i<=n;i++)
	{
		int stt;
		int sum=0;
		for (int j=1;j<=n;j++)
		{
			if (c[i][j]=='.')
			{
				if (sum==0) stt=j;
				sum++;
//				cout << ")))" << i << " " << j << " " << sum << endl;
			}
			else
			{
				if (sum>=mid)
				{
//					cout << "***" << mid << " " << i << " " << stt << " " << j-1 << endl;
					cnth++;
					hang[cnth].st=stt;
					hang[cnth].en=j-1;
					hang[cnth].wei=i;
					if (j-stt>=2*mid) return true;
				}
				sum=0;
			}
		}
		if (sum>=mid)
		{
			cnth++;
			hang[cnth].st=stt;
			hang[cnth].en=n;
			hang[cnth].wei=i;
			if (n-stt+1>=2*mid) return true;
		}
	}
	int cntl=0;
	for (int i=1;i<=n;i++)
	{
		int stt=0;
		int sum=0;
		for (int j=1;j<=n;j++)
		{
			if (c[j][i]=='.')
			{
				if (sum==0) stt=j;
				sum++;
			}
			else
			{
				if (sum>=mid)
				{
//					cout << "(((***" << i << " " << stt << " " << j-1 << endl;
					cntl++;
					lie[cntl].st=stt;
					lie[cntl].en=j-1;
					lie[cntl].wei=i;
					if (j-stt>=2*mid) return true;
				}
				sum=0;
			}
		}
		if (sum>=mid)
		{
			cntl++;
			lie[cntl].st=stt;
			lie[cntl].en=n;
			lie[cntl].wei=i;
			if (n-stt+1>=2*mid) return true;
		}
	}
//	cout << "&&&" << mid << " " << cnth << " " << cntl << endl;
	if (cntl>=2 || cnth>=2) return true;
	if (cntl==0 || cnth==0) return false;
	if (lie[1].en<hang[1].wei || lie[1].st>hang[1].wei || hang[1].en<lie[1].wei || hang[1].st>lie[1].wei || (max(lie[1].wei-hang[1].st,hang[1].en-lie[1].wei)>=mid && max(hang[1].wei-lie[1].st,lie[1].en-hang[1].wei)>=mid)) return true;
	return false;
}

int main()
{
//	freopen("color.in","r",stdin);
//	freopen("color.out","w",stdout);
	cin >> n;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			cin >> c[i][j];
	int l=1,r=n;
	int ans=-1;
	while (l<=r)
	{
		int mid=(l+r)/2;
		if (chk(mid))
		{
			ans=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	cout << ans << endl;
	
	return 0;
}
原文