题解:P12340 [蓝桥杯 2025 省 AB/Python B 第二场] 旗帜

· · 题解

思路

纯模拟,找到这面旗帜长什么样,统计 A 的数量即可,我们可以用 cnt 来确认这是第几个字母,在为 26 时即为 A。

#include<bits/stdc++.h>
using namespace std;
int cnt=0,ans=0;
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int h,w;
    cin>>h>>w;
    for(int i=1;i<=h;i++){
        cnt=(i-1)%7;
        for(int j=1;j<=w;j++){
            cnt++;
            if(cnt==8) cnt=1;
            if(cnt==2||cnt==6) ans++;
        }
    }
    cout<<ans;
    return 0;
}