跳到正文

个人记录

总结(代码)

wuweize150815约 6 分钟
原文
文章信息与版本

文章信息

发布
2026年8月20日
收录
2026年8月20日
更新
2026年8月21日
篇幅
约 6 分钟

版本

  1. v1当前

代码

这里有着珍贵的ACAC代码呦

T809250 黑白棋

C++
#include <bits/stdc++.h>
using namespace std;
long long n , s;
int main ( )
{
	//freopen ("reversi.in" , "r" , stdin);
	//freopen ("reversi.out" , "w" , stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	s=sqrt (n);
	cout << s << " " << s*s;
	return 0;
}

T809254 游戏订阅系统

C++
#include <bits/stdc++.h>
#define int long long
using namespace std;
int v[200005];
int a[100005];
int n , maxn=0 , tot , id;
signed main ( )
{
	//freopen ("game.in" , "r" , stdin);
	//freopen ("game.out" , "w" , stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i=1;i<=n;i++)
	{
		cin >> a[i];
		v[++tot]=a[i]-1;
		v[++tot]=a[i];
	}
	sort (v+1 , v+tot+1);
	tot=unique (v+1 , v+tot+1)-(v+1);
	sort (a+1 , a+n+1);
	for (int i=1;i<=tot;i++)
	{
		int s=v[i];
		int pos=lower_bound (a+1 , a+n+1 , s)-a;
		int w=s*(n-pos+1);
		if (w>maxn)
		{
			maxn=w;
			id=s;
		}
	}
	cout << maxn << " " << id;
	return 0;
}

T809257 删除注释

C++
#include <bits/stdc++.h>
using namespace std;
string s , t;
int n , m;
bool flag=0;
int main ( )
{
	//freopen ("comment.in" , "r" , stdin);
	//freopen ("comment.out" , "w" , stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	getline (cin , s);
	while (n--)
	{
		getline (cin , s);
        m=s.size ( );
		for (int i=0;i<=m-1;i++)
        {
            if (flag==1)
            {
                if (i<m-1&&s[i]=='*'&&s[i+1]=='/')
                {
                    flag=0;
                    i++;
                }
            }
            else
            {
                if (i<m-1&&s[i]=='/'&&s[i+1]=='/')
                {
                    break;
                }
                if (i<m+1&&s[i]=='/'&&s[i+1]=='*')
                {
                    flag=1;
                    i++;
                }
                else
                {
                    t+=s[i];
                }
            }
        }
        if (flag==0&&t!="")
        {
            cout << t << "\n";
            t="";
        }
	} 
	return 0;
}

T809262 数组划分

C++
#include <bits/stdc++.h>
using namespace std;
long long dp[200005] , s[200005];
int id[200005];
int v[200005];
int n , m;
long long ci (int k)
{
    return (long long) k*k*k*k;
}
int main ( )
{
	//freopen ("array.in" , "r" , stdin);
	//freopen ("array.out" , "w" , stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for (int i=1;i<=n;i++)
	{
		cin >> v[i];
        s[i]=s[i-1]+v[i];
	}
    for (int i=1;i<=n;i++)
    {
        id[v[i]]=i;
        dp[i]=dp[i-1];
        int minn=1e9;
        for (int j=0;j<=m;j++)
        {
            if (id[j]==0) break;
            minn=min (minn , id[j]);
            if (s[i]-s[minn-1]>m) break;
            dp[i]=max (dp[i] , dp[minn-1]+ci (j+1));
        }
    }
	cout << dp[n];
	return 0;
}
原文