跳到正文

个人记录

78总结

yangchunsheng约 4 分钟
原文
文章信息与版本

文章信息

收录
2026年7月9日
更新
2026年7月9日
篇幅
约 4 分钟

版本

  1. v2当前
  2. v1

as01

思路

用双指针找左端点能延伸到的最大右端点,用前缀和求区间和,最后检查一下边界,找到最大值就可以了

100分

C++
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
int t,n,l,r,s,a[200005],b[200005],sum[200005];
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--)
	{
		l=1;
		r=0;
		s=0;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			sum[i]=sum[i-1]+a[i];
		}
		for(int i=1;i<=n;i++)cin>>b[i];
		while(l<=n)
		{
			int ls=a[l]+b[l];
			while(r<n&&a[r+1]+b[r+1]==ls)r++;
			s=max(s,(r-l+1)*(sum[r]-sum[l-1]));
			l=r+1;
		}
		cout<<s<<endl;
	}
	return 0;
}

as03

思路

每个A在没有被单个B或C阻挡的情况下都可以影响到它后面的所有BC,所以我们需要统计A出现的次数,遇到BC就将最终答案加上A出现的次数,如果被阻挡就把A出现的次数清0,最后输出答案就可以了

100分

C++
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string a;
	int s=0,cnt=0;
	cin>>a;
	for(int i=0;i<a.size()-1;i++)
	{
		if(a[i]=='A')
		{
			cnt++;
		}
		else if(a[i]=='B'&&a[i+1]=='C')
		{
			s+=cnt;
			i++;
		}
		else 
		{
			cnt=0;
		}
	}
	cout<<s;
	return 0;
}

as04

题意

正向考虑删除边过于麻烦,我们不妨考虑保留每一组边的代码,一组映射就可以唯一确定这一组边的保留情况,所以只要全排列映射的情况就行了,但是保留的边可能是相同的,所以我们用二进制存储该状态是否被记录过,不是的话就标记该状态

100分

C++
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
int n,n1,m,m1,a[10][10],b[10][10],f[10],s=0;
map<int,int>ma;
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>n1>>m>>m1;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		a[y][x]=1;
		a[x][y]=1;
	}
	for(int i=1;i<=m1;i++)
	{
		int x,y;
		cin>>x>>y;
		b[y][x]=i;
		b[x][y]=i;
	}
	if(n!=n1)
	{
		cout<<0;
		return 0;
	}
	for(int i=1;i<=n;i++)f[i]=i;
	do
	{
		int ls=1;
		long long bj=0;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(a[i][j])
				{
					if(b[f[i]][f[j]]==0)
					{
						ls=0;
					}
					bj|=(1<<b[f[i]][f[j]]);
				}
			}
		}
		if(ls&&ma[bj]==0)
		{
			ma[bj]=1;
			s++;
		}
	}
	while(next_permutation(f+1,f+n+1));
	cout<<s;
	return 0;
}
原文