8.28_407_课堂总结

· · 个人记录

U593675 查找数

\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 n, a, b;
    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        if(x == a + b){
            cout << i << "\n";
        }
    }
    return 0;
}

U593858 数叉叉

\color{52c41a} 100pts

思路

模拟

代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n, m;
char c[111][111];
map<int, int> mp;

int check(int x, int y){
    for(int i = 1; i <= min(n, m); i++){
        if(x - i <= 0 || y - i <= 0 || x + i > n || y + i > m || !(c[x + i][y + i] == '#' && c[x + i][y - i] == '#' && c[x - i][y + i] == '#' && c[x - i][y - i] == '#')){
            int j = i;
            while(j--){
                if(c[x + j + 1][y + j + 1] != '#' && c[x + j + 1][y - j - 1] != '#' && c[x - j - 1][y + j + 1] != '#' && c[x - j - 1][y - j - 1] != '#'){
                    return j;
                }
            }
            return 0;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> c[i][j];
        } 
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(c[i][j] == '#'){
                mp[check(i, j)]++;
            }
        }
    }
    for(int i = 1; i <= min(n, m); i++){
        cout << mp[i] << ' ';
    }
    return 0;
}

T661095 结算日

\color{e74c3c} 0pts

BFS没写好

思路

前缀和 + 贪心

代码

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n, a[100001], sum[100001];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    ll id = 0, ans = 0;
    bool q = false;
    for(int i = 1; i <= n; i++){
        sum[i] = sum[i - 1] + a[i];
        ans++;
        if(a[i] < 0){
            if(!q){
                q = true;
                id = i;
            }
        }else if(sum[i] >= 0 && q){
            q = false;
            ans += (i - id) * 2;
        }
    }
    cout << ans;
    return 0;
}

U593859 落落的去的数学问题六

\color{e74c3c} 12pts

暴力

思路

埃筛 + 枚举(剪枝)

代码

#include<bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;
int zs[500001], zzs[300001];
map<ll, bool> mp;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, cnt = 0;
    cin >> n;
    zs[1] = 1;
    for(ll i = 2; i <= 400001; i++){
        if(!zs[i]){
            zzs[++cnt] = i;
            for(ll j = i * i; j <= 400001; j += i){
                zs[j] = 1;  
            }
        }
    }
    ll ans = 0;
    for(int i = 1; ; i++){
        if(pow(zzs[i], 5) > n){
            break;
        }
        for(int j = i + 1; ; j++){
            if(pow(zzs[i], 2) * pow(zzs[j], 3) > n){
                break;
            }
            for(int k = j + 1; k <= sqrt(n); k++){
                ll kk = pow(zzs[i], 2) * zzs[j] * pow(zzs[k], 2);
                if(kk > n){
                    break;
                }
                if(kk <= n){
                    ans++;
                }
            }
        }
    }
    cout << ans;
    return 0;
}