跳到正文

个人记录

5.22

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

文章信息

收录
2026年5月29日
更新
2026年5月29日
篇幅
约 5 分钟

版本

  1. v1当前

题目总结:

B4522 [语言月赛 202604] 礼堂预约 II

题目

考察知识点:

if判断

思路:

  • 如果 [a,b)[a, b) 被 [8,12)[8,12) 包含 → 输出 MM
  • 否则如果被 [13,17)[13,17) 包含 → 输出 AA
  • 否则如果被 [18,21)[18,21) 包含 → 输出 EE
  • 否则输出 FF

代码:

C++
#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
	cin>>a>>b;
    if(a>=8 and b<=12 and a<=12 and b>=8)
	{
		cout<<"M";
	}
	else if(a>=13 and b<=17 and a<=17 and b>=13)
	{
		cout<<"A";
	}
	else if(a>=18 and b<=21 and a<=21 and b>=18)
	{
		cout<<"E";
	}
	else
	{
		cout<<"F";
	}
	return 0;
} 

P15927 [TOPC 2023] Kick

题目

考察知识点:

字符串

思路:

输入一个字符串,遍历整个字符串,统计字符串里不同字串 kickkick 的数量。

代码:

C++
#include<bits/stdc++.h>
using namespace std;
string s;
int cnt=0;
int main()
{
	cin>>s;//输入字符串
	for(int i=0;i<s.size()-3;i++)
	{
		if(s[i]=='k' and s[i+1]=='i' and s[i+2]=='c' and s[i+3]=='k')cnt++;
	}
	cout<<cnt;//输出子串的数量
	return 0;
}

P16556 [ICPC 2026 LAC] Jaime’ s Palace

题目

考察知识点:

栈

思路:

对于每一次操作,先将前几个元素的被取出次数加 11,然后将前几个元素按被取出次数降序放入栈里,这样可以让被取出次数少的放在前面,被取出次数数多的放在后面。

代码:

C++
#include<bits/stdc++.h>
using namespace std;
int p,d,a[11111],maxx=0;
int main()
{
	cin>>p>>d;
	while(d--)
	{
        int x;
		cin>>x;
        sort(a+1,a+x+1);//排序
        for(int i=1;i<=x;i++)
        {
            a[i]++;
            maxx=max(maxx,a[i]);//取最大值
        }
	}
    cout<<maxx;//输出最大值
	return 0;
}

T763330 月色的真假钥匙

题目

考察知识点:

DFS

思路:

用 DFSDFS 枚举所有钥匙的真假组合,对每种组合检查是否与所有测试结果一致,统计合法组合数。

代码:

C++
#include<bits/stdc++.h>
using namespace std;
int vis[20],n,m,k,ans;
char op[110];
vector<int>a[110];
void dfs(int x)
{
    if(x==n+1)
    {   
        for(int i=1;i<=m;i++)
        {
            int cnt=0;//cnt:真钥匙的数量
            for(int j=0;j<a[i].size();j++)
            {
                if(vis[a[i][j]]==1)
                {
                   cnt++; 
                }
            }
            if(op[i]=='o' and cnt>=k)continue;
            if(op[i]=='x' and cnt<k)continue;
            return;
        }
        ans++;
        return;
    }
    //选
    vis[x]=1;
    dfs(x+1);
    vis[x]=0;
    //不选
    dfs(x+1);
}
int main()
{
	cin>>n>>m>>k;
    for(int i=1;i<=m;i++)
    {
        int xx;
        cin>>xx;
        while(xx--)
        {
            int yy;
            cin>>yy;
            a[i].push_back(yy);
        }
        cin>>op[i];
    }
    dfs(1);
    cout<<ans;
	return 0;
}
原文