题解:P12654 [KOI 2023 Round 1] 奶油面包

· · 题解

传送门

P12654 [KOI 2023 Round 1] 奶油面包

我首先要强调:不要被样例迷惑了,第二行看似是一排数,其实是没换行的矩阵!
比如:

2 3 2
1 1 0 1 0 0

其实是:

2 3 2
1 1 0
1 0 0

那就解决一半了。整个 sum,统计每一组没加奶油的面包,最后判断并累加计数器就完事了!
完整代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0)->sync_with_stdio(0);
    cout.tie(0);
    int cnt = 0,sum,x,n,k,p;//如文中所说
    cin>>n>>k>>p;
    for(int i = 1;i<=n;i++){//当成矩阵输入
        sum = 0;//清空,千万记得!
        for(int j = 1;j<=k;j++){//当成矩阵输入
            cin>>x;
            sum+=(!x);//统计没加奶油的
        }
        cnt+=int(sum<p);//判断,等价于if(sum<p)cnt++;
    }
    cout<<cnt;
    return 0;
}