跳到正文

算法·理论

2.28-小六集训队-407

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

文章信息

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

版本

  1. v4当前
  2. v3
  3. v2
  4. v1

T1

第一题依旧简单

巴巴博弈

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
string OI1_is1="我不是人工智能,但你猜我为什么要写";//迷惑行为
const int N=1e5+7;
int n;
signed main()
{
	int T;
	cin>>T;
	while(T--)
	{
		cin>>n;
		cout<<n-1<<" "<<n/2<<endl;
	}
	return 0;
}

T2

第二题想了老久还是没想明白,最后想了个歪法子

40分代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+7;
int cnt=0;
signed main()
{
	string s;
	cin>>s;
	bool vis=0;
	while(1)
	{
		string a=s;
		for(int i=0;i<s.size()-1;i++)
		{
			if(s[i]=='B'&&s[i+1]=='W')
			{
				s[i]='W',s[i+1]='B';
				cnt++;
			}
		}
		if(a==s)break;
	}
	cout<<cnt;
	return 0;
}

man分代码

细节贴劳达图片证明自己不是ai生成的文案

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
    string s;
    cin >>s;
    int n=n.size();
    int ans=0;
    int cnt=0;
    for(int i=n-1;i>=0;i--)
	{
        if(s[i]=='W')
		{
            cnt++;
        }
		else
		{
            ans+=cnt;
        }
    }
    cout<<ans<<endl;
    return 0;
}

T3

一道5分钟写出来的题

代码

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e3+7;
int a[N][N];
int n;
int maxn=-1e9;
int df(int x,int y)
{
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		sum+=a[x][i];
	}
	for(int i=1;i<=n;i++)
	{
		sum+=a[i][y];
	}
	return sum;
}
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(a[i][j]==0)
			{
				maxn=max(maxn,df(i,j));
			}
		}
	}
	if(maxn!=-1e9)cout<<maxn;
	else cout<<"Bad Game!" ;
	return 0;
}
/*
4
1 1 1 0
1 1 1 1
1 1 1 1
0 1 1 1

*/

T4

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
priority_queue<int,vector<int>,greater<int>> a;
priority_queue<int> b;
signed main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        a.push(x);
    }
    for(int i=1;i<=m;i++)
    {
        int x;
        cin>>x;
        b.push(x);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int x=a.top();
        a.pop();
        int cnt=0;
        while(b.size()&&cnt<b.top())
        {
            b.pop();
            cnt++;
            ans+=x;
        }
    }
    if(b.size()) cout<<-1;
    else cout<<ans;
    return 0;
}
原文