跳到正文

个人记录

5.15<来追梦信息学407蒋老师>课堂总结

XieMuzhu约 7 分钟
原文

这是 2026年5月17日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年5月16日
收录
2026年5月17日
更新
2026年11月11日
篇幅
约 7 分钟

版本

  1. v3当前
  2. v2
  3. v1

B3781 [语言月赛202306] 信

题意:

不再过多赘述,就是一个简单的模拟

思路:

模拟

注意
  • 记得开longlong longlong,否则 WA\color{red} \displaystyle \texttt{WA} 66个点。
  • 要按题意模拟

详情见注释

代码:

C++
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, x, y, a, b, S, s, M, ans, cnta, cntb, now;
signed main(){
	cin >> n >> x >> y >> a >> b;
	for(int i = 1; i <= n; i++){
		cin >> S >> s >> M;
        int m = M - S * x - s * y;//礼物有多重
        if(m){//有礼物
            cnta++, cntb = 0;//多了一个有礼物的信
            now += m;
            if(m > S * x + s * y) now += (m + 1) / 2;//礼物的质量大于信封和信纸的总质量,则会额外增加0.5礼物重量
            if(cnta >= a) now *= 2;////连续a封及以上的信里都没有礼物,惊喜值×2
            ans = max(ans, now);//取最大惊喜值
        }
        else{//没有礼物
            cntb++, cnta = 0;//多了一个没有礼物的信
            if(cntb >= b) now /= 2;//连续b封及以上的信里都没有礼物,惊喜值减半
        }
    }
    cout << ans << ' ' << now;
	return 0;
}

P2327 [SCOI2005] 扫雷

题意:

一维扫雷,分为两列,左边要填雷,以保证右边那一列每个数的八方向为左边那一列雷的个数。
求有多少种不同的方案以保证符合规则。

思路:

我用的不是模拟,用的是dfsdfs。这里我来讲一下dfsdfs的思路。
我们根据原题面的图片,将左边第一列的第一个格子分为两种情况:填雷、不填雷。由此我们可以推出答案只能分为三种情况:00种方案,11种方案,22种方案。
然后呢,就是一个选或不选,接着我们只需要判断此时此刻能否符合规则,最后只需要在搜完了之后判断是否可行。
其实这道题是做过的,也很水,就是考试的时候没想到

代码:

C++
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int n, ans, a[N], b[N];
int pd(int x){
    if(b[x - 1] + b[x] + b[x + 1] == a[x]) return true;//符合规则
    else return false;//不符合规则
}
void dfs(int step){
    if(step == n + 1){//搜完了
        if(pd(n)) ans++;//多一种方案
        return;
    }
    b[step] = true;//选
    if(step == 1 || pd(step - 1)) dfs(step + 1);//继续搜
    b[step] = false;//不选
    if(step == 1 || pd(step - 1)) dfs(step + 1);//继续搜
}
int main(){
	cin >> n;
	for(int i = 1; i <= n; i++)	
		cin >> a[i];
	dfs(1);//从第1个开始搜
	cout << ans;
	return 0;
}

T761164 日期

题意:

给定一个日期abab-cdcd,然而这个日期并不一定出现在日历上面,所以要改若干位(含00位)数字,使得这个日期存在。
问至少要改多少位数字

思路:

代码:

C++
#include <bits/stdc++.h>
using namespace std;
int t, day[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
void solve(){
    char a, b, c, e;
    cin >> a >> b >> c >> c >> e;
    int m = (a - '0') * 10 + (b - '0');
    int d = (c - '0') * 10 + (e - '0');
    int ans = 0;
    if(!d || d > 31)
        if(!m || m > 12) ans = 2;
        else ans = 1;
    else if(d == 31)
        if(day[m] == 31) ans = 0;
        else if(m == 2 || m == 4 || m == 6 || m == 9 || m == 11 || !m || m >= 13 || m <= 19) ans = 1;
        else{
            int x = m % 10;
            if(x < 4 || x == 5 || x == 7 || x == 8 || x >= 13 && x <= 19) ans = 1;
            else ans = 2;
        }
    else if(d == 29 || d == 30)
        if(m == 2 || m > 12 || m == 0) ans = 1;
        else ans = 0;
    else
        if(!m || m > 12) ans = 1;
        else ans = 0;
    cout << ans << '\n';
}
int main(){
	cin >> t;
	while(t--) solve();
	return 0;
}

T761206 删字符

题意:

思路:

代码:

C++
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int t, n, m, cnt, ans, num[N];
string s;
map <string, int> f;
void solve(){
    cin >> n >> s;
    memset(num, 0, sizeof(num));
    cnt = ans = 0;
    for(int i = 1; i <= n; i++){
        num[s[i - 1]]++;
        if(num[s[i - 1]] == 1) cnt++;
        ans += cnt;
    }
    cout << ans << '\n';
}
int main(){
	cin >> t;
	while(t--) solve();
	return 0;
}