8.19_407_课堂总结

· · 个人记录

T638414 营养达标

传送门

\color{#52c41a} 100pts

思路

简单模拟

正解代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[101], b[101];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            int x;
            cin >> x;
            b[j] += x;
        }
    }
    for(int i = 1; i <= m; i++){
        if(b[i] < a[i]){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

T638487 打扫卫生

传送门

\color{#52c41a} 100pts

思路

模拟

正解代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<string> s;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    if(k > n || k > m){
        cout << -1;
        return 0;
    }
    int Cnt = 0;
    for(int i = 1; i <= n; i++){
        int cnt = 0;
        string ss = "";
        for(int j = 1; j <= m; j++){
            char c;
            cin >> c;
            ss += c;
            if(c == '*'){
                cnt++;
            }
        }
        s.push_back(ss);
        if(cnt % k != 0){
            cout << -1;
            return 0;
        }
        Cnt += cnt;
    }
    for(int i = 1; i <= m; i++){
        int cnt = 0;
        for(int j = 0; j < n; j++){
            if(s[j][i] == '*'){
                cnt++;
            }
        }
        if(cnt % k != 0){
            cout << -1;
            return 0;
        }
    }
    cout << Cnt / k / k; 
    return 0;
}

T643658 落落的去的数学颖1

传送门

\color{#52c41a} 100pts

思路

数学,推出公式即可

正解代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int a, b, c, ans = 0;
    cin >> a >> b >> c;
    int l = b;
    if(a == b){
        l++;
        ans = 1;
    }else{
        ans = 2;
    }
    ans += l - c - 1;
    cout << ans;
    return 0;
}

T640726 落落的去的围栏

传送门

\color{#f39c11} 30pts

正解思路

用二分查找满足的颜料的数量,再算出答案

正解代码

#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[200001], n, m, ans;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        cin >> n >> m;
        ans = 0;
        for(int i = 1; i <= m; i++){
            cin >> a[i];
        }
        stable_sort(a + 1, a + m + 1);
        for(int i = 1; i < n; i++){
            int h = m - (lower_bound(a + 1, a + m + 1, i) - a) + 1;
            int hh = m - (lower_bound(a + 1, a + m + 1, n - i) - a) + 1;
            ans += h * hh - min(h, hh);
        }
        cout << ans << "\n";
    }
    return 0;
}