头像

qing_cai




离线:21小时前


最近来访(12)
用户头像
Wdydxzn
用户头像
ㅤ_049
用户头像
无情空余心
用户头像
深色的云
用户头像
牛马工厂
用户头像
Kanam
用户头像
kspsy
用户头像
laigaobacc
用户头像
神威_1

活动打卡代码 AcWing 3428. 放苹果

// #pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
// #define int long long
using namespace std;

#ifdef LOCAL
#include "/Myfunc/debug.h"
#else
#define pr(...) 33
#endif

#define sp ' '
#define endl '\n'
#define pb push_back

#define mod(x) (x) % mod
#define all(x) (x).begin(), (x).end()

#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> PII;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

int n, m;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(cin >> n >> m){
        int f[11][11] = {0};
        f[0][0] = 1;
        rep(i, 0, n) rep(j, 1, m){
            f[i][j] = f[i][j-1];
            if(i >= j)
                f[i][j] += f[i-j][j];
        }
        cout << f[n][m] << endl;
    }
    return 0;
}


活动打卡代码 AcWing 1273. 天才的记忆

// #pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
// #define int long long
using namespace std;

#ifdef LOCAL
#include "/Myfunc/debug.h"
#else
#define pr(...) 33
#endif

#define sp ' '
#define endl '\n'
#define pb push_back

#define mod(x) (x) % mod
#define all(x) (x).begin(), (x).end()

#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> PII;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

int n, m;
int st[N][23], a[N];

void init(){
    rep(i, 1, n) st[i][0] = a[i];

    rep(j, 1, 21) for(int i = 1; i + (1 << j) - 1 <= n; i ++)
    st[i][j] = max(st[i][j - 1], st[i + (1 << j - 1)][j - 1]);
}
int get(int l, int r){
    int k = log2(r - l + 1);
    return max(st[l][k], st[r - (1 << k) + 1][k]);
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;

    rep(i, 1, n) cin >> a[i];
    init(); cin >> m;

    rep(i, 1, m){
        int l, r; cin >> l >> r;
        cout << get(l, r) << endl;
    }
    return 0;
}



C++ 代码

// #pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
// #define int long long
using namespace std;

#ifdef LOCAL
#include "/Myfunc/debug.h"
#else
#define pr(...) 33
#endif

#define sp ' '
#define endl '\n'
#define pb push_back

#define mod(x) (x) % mod
#define all(x) (x).begin(), (x).end()

#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> PII;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

int n, m;
int l[N], f[N];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    while(cin >> n){
        rep(i, 1, n) cin >> f[i];
        rep(i, 1, n) l[i] = i;

        rep(i, 1, n){
            if(0 <= f[i - 1]) f[i] = f[i - 1] + f[i], l[i] = l[i - 1];
        }

        int L = 0, r = 0, res = -1e9;
        rep(i, 1, n){
            if(res < f[i]) L = l[i], r = i, res = f[i];
        }

        if(res < 0) cout << "0 0 0" << endl;
        else cout << res << sp << L - 1 << sp << r - 1 << endl;
    }

    return 0;
}



活动打卡代码 AcWing 1015. 摘花生

qing_cai
10天前
// #pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
// #define int long long
using namespace std;

#ifdef LOCAL
#include "/Myfunc/debug.h"
#else
#define pr(...) 11
#endif

template<typename T> inline T read(){
    T x = 0, f = 0; char ch = cin.get();
    while (!isdigit(ch)) f |= ch=='-', ch = cin.get();
    while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = cin.get();
    return f ? -x : x;
}
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}

#define sp ' '
#define endl '\n'
#define pb push_back

#define mod(x) (x) % mod
#define read() read<int>()
#define all(x) (x).begin(), (x).end()

#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> PII;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e4 + 10;

int _, n, m;
int g[N][N];
int f[N][N];

void solve(){
    cin >> n >> m;

    rep(i, 1, n) rep(j, 1, m) cin >> g[i][j];

    rep(i, 1, n) rep(j, 1, m)
    f[i][j] = max(f[i - 1][j] + g[i][j], f[i][j - 1] + g[i][j]);

    cout  << f[n][m] << endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> _; // _ = 1;
    while(_--) solve();
    return 0;
}


活动打卡代码 AcWing 4269. 校庆

qing_cai
12天前
// #pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
// #define int long long
using namespace std;

#ifdef LOCAL
#include "/Myfunc/debug.h"
#else
#define pr(...) 11
#endif

template<typename T> inline T read(){
    T x = 0, f = 0; char ch = cin.get();
    while (!isdigit(ch)) f |= ch=='-', ch = cin.get();
    while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = cin.get();
    return f ? -x : x;
}
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}

#define sp ' '
#define endl '\n'
#define pb push_back
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define out(x) cout << (x) << endl

#define mod(x) (x) % mod
#define read() read<int>()
#define all(x) (x).begin(), (x).end()

#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> PII;
typedef unsigned long long ull;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;

int n, m;
unordered_map<string, int> mp;

struct Node{
    string s;
    string year;
}node[N];
struct Come{
    string s;
    string year;
}come[N];

bool cmp(Node &x, Node &y){
    return x.year < y.year;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    int cnt = 0;
    rep(i, 1, n){
        string s; cin >> s;
        mp[s] = 1;
    }

    cin >> m;
    int num = 0, cntt = 0;
    rep(i, 1, m){
        string s; cin >> s;
        if(num == 0){
            come[++cntt].s = s;
            come[cntt].year = s.substr(6, 8);
        }
        if(mp.count(s)){
            num ++;
            node[++cnt].s = s;
            node[cnt].year = s.substr(6, 8);
        }
    }

    sort(node + 1, node + cnt + 1, cmp);
    if(num == 0) sort(come + 1, come + cntt + 1, [&] (Come &x, Come &y){
                                    return x.year < y.year;
                                });
    out(num);
    if(num == 0) out(come[1].s);
    else out(node[1].s);
    return 0;
}


活动打卡代码 AcWing 4268. 性感素数

qing_cai
12天前
// #pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
// #define int long long
using namespace std;

#ifdef LOCAL
#include "/Myfunc/debug.h"
#else
#define pr(...) 11
#endif

template<typename T> inline T read(){
    T x = 0, f = 0; char ch = cin.get();
    while (!isdigit(ch)) f |= ch=='-', ch = cin.get();
    while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = cin.get();
    return f ? -x : x;
}
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}

#define sp ' '
#define endl '\n'
#define pb push_back
#define NO cout << "No" << endl
#define YES cout << "Yes" << endl
#define out(x) cout << (x) << endl

#define mod(x) (x) % mod
#define read() read<int>()
#define all(x) (x).begin(), (x).end()

#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> PII;
typedef unsigned long long ull;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;

int n, m;

bool func(int x){
    if(x <= 1) return false;

    for(int i = 2; i <= x / i; i ++)
        if(x % i == 0) return false;
    return true;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;

    if(func(n) && func(n - 6)) YES, out(n - 6);
    else if(func(n) && func(n + 6)) YES, out(n + 6);
    else {
        for(int i = n + 1; ; i ++){
            if(func(i) && (func(i + 6) || func(i - 6))){
                NO, out(i);
                return 0;
            }
        }
    }
    return 0;
}


活动打卡代码 AcWing 1052. 设计密码

qing_cai
1个月前
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
typedef pair<int, int> PII;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 55;
int n, m, ne[N];
int f[N][N];
char p[N];

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> (p + 1);
    m = strlen(p + 1);
    for(int i = 2, j = 0; i < m; i++){
        while(j && p[i] != p[j + 1]) j = ne[j];
        if(p[i] == p[j + 1]) j ++;
        ne[i] = j;
    }
    f[0][0] = 1;
    for(int i = 1; i <= n; i++)
        for(int j = 0; j < m; j++)
            for(char k = 'a'; k <= 'z'; k++){
                int u = j;
                while(u && k != p[u + 1]) u = ne[u];
                if(k == p[u + 1]) u ++;
                if(u < m) f[i][u] = (f[i][u] + f[i - 1][j]) % mod;
            }
    int res = 0;
    for(int i = 0; i < m; i++)
        res = (res + f[n][i]) % mod;
    cout << res << endl;
    return 0;
}


活动打卡代码 AcWing 1058. 股票买卖 V

qing_cai
1个月前
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
typedef pair<int, int> PII;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
int n, m;
int w[N];
int f[N][3];

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> w[i];
    f[1][0] = -w[1];
    for(int i = 2; i <= n; i++){
        f[i][0] = max(f[i - 1][0], f[i - 1][2] - w[i]);
        f[i][1] = f[i - 1][0] + w[i];
        f[i][2] = max(f[i - 1][1], f[i - 1][2]);
    }
    cout << max(f[n][1], f[n][2]) << endl;
    return 0;
}


活动打卡代码 AcWing 1057. 股票买卖 IV

qing_cai
1个月前
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
typedef pair<int, int> PII;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
int n, k, m, w[N];
int dp[N][110][2];

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> w[i];
    memset(dp, -0x3f, sizeof dp);
    for(int i = 1; i <= n; i++)
        dp[i][0][0] = 0, dp[i][0][1] = -w[i];
    for(int i = 2; i <= n; i++){
        for(int j = 0; j <= k; j++){
            if(j >= 1) dp[i][j][0] = max(dp[i - 1][j - 1][1] + w[i], dp[i - 1][j][0]);
            else dp[i][j][0] = dp[i - 1][j][0];
            dp[i][j][1] = max(dp[i - 1][j][0] - w[i], dp[i - 1][j][1]);
        }
    }
    int res = 0;
    for(int i = 0; i <= k; i++)
        res = max(res, dp[n][i][0]);
    cout << res << endl;
    return 0;
}


活动打卡代码 AcWing 1049. 大盗阿福

qing_cai
1个月前
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
typedef pair<int, int> PII;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
int n, m, w[N];
int dp[N][2];

void solve(){
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> w[i];
    dp[1][0] = 0; dp[1][1] = w[1];
    for(int i = 2; i <= N; i ++){
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][0]);
        dp[i][1] = dp[i - 1][0] + w[i];
    }
    cout << max(dp[n][1], dp[n][0]) << endl;
}
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int _; cin >> _;
    while(_--) solve();
    return 0;
}