头像

背书包的小新




离线:18小时前


最近来访(68)
用户头像
LLP2333
用户头像
Dinas
用户头像
yangk
用户头像
abc_9
用户头像
打铁选手
用户头像
Stoner_8
用户头像
罗磁
用户头像
Acwing-一尘不染
用户头像
zhugeqing
用户头像
klxx
用户头像
网名是个负担
用户头像
种花家的小兔子
用户头像
Q_83
用户头像
罗江华
用户头像
晨灼灼
用户头像
香香小马
用户头像
euuuammxzm
用户头像
@Moli
用户头像
空白_74
用户头像
尔玉

活动打卡代码 AcWing 1904. 奶牛慢跑

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int n;
int a[N];
int ans;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        a[i] = r;
    }
    a[n + 1] = 0x3f3f3f3f;
    for (int i = n; i >= 1; i--)
    {
        if (a[i] <= a[i + 1])
        {
            ans++;
        }
        else
        {
            a[i] = a[i + 1];
        }
    }
    cout << ans;
    return 0;
}



#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b, c, d;
ll ans = 0x3f3f3f3f3f3f3f3f;
char s[3];
void dfs(vector<ll> v1, int step)
{
    if (v1.size() == 1)
    {
        ans = min(ans, v1[0]);
        return;
    }
    vector<ll>v3;
    for(int i=0;i<v1.size();i++)
    v3.push_back(v1[i]);
    for (int i = 0; i < v1.size() - 1; i++)
    {
        for (int j = i + 1; j < v1.size(); j++)
        {
            if(s[step]=='*')
            v1.push_back(v1[i]*v1[j]);
            else
            v1.push_back(v1[i]+v1[j]);
            v1.erase(v1.begin()+i);
            v1.erase(v1.begin()+j-1);
            dfs(v1,step+1);
            while(v1.size())
            v1.pop_back();
            for(int k=0;k<v3.size();k++)
            v1.push_back(v3[k]);
        }
    }
}
int main()
{
    vector<ll> v;
    cin >> a >> b >> c >> d;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);
    cin >> s[0] >> s[1] >> s[2];
    dfs(v, 0);
    cout << ans;
    return 0;
}



#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e3 + 10;
int n;
ll s[N];
ll c[N];
ll ans = 1e10;
int f = 1;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> s[i];
    for (int j = 1; j <= n; j++)
        cin >> c[j];
    for (int i = 2; i <= n - 1; i++)
    {
        ll a = 1e10, b = 1e10;
        for (int j = 1; j < i; j++)
        {
            if (s[j] < s[i])
                a = min(a, c[j]);
        }

        for (int k = i + 1; k <= n; k++)
        {
            if (s[k] > s[i])
                b = min(b, c[k]);
        }
        ans = min(ans, c[i] + a + b);
    }
    if (ans == 1e10)
        cout << -1;
    else
        cout << ans;
    return 0;
}


活动打卡代码 AcWing 4214. 三元组

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e3 + 10;
int n;
ll s[N];
ll c[N];
ll ans = 1e10;
int f = 1;
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> s[i];
    for (int j = 1; j <= n; j++)
        cin >> c[j];
    for (int i = 2; i <= n - 1; i++)
    {
        ll a = 1e10, b = 1e10;
        for (int j = 1; j < i; j++)
        {
            if (s[j] < s[i])
                a = min(a, c[j]);
        }

        for (int k = i + 1; k <= n; k++)
        {
            if (s[k] > s[i])
                b = min(b, c[k]);
        }
        ans = min(ans, c[i] + a + b);
    }
    if (ans == 1e10)
        cout << -1;
    else
        cout << ans;
    return 0;
}


活动打卡代码 AcWing 4213. 最小结果

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b, c, d;
ll ans = 0x3f3f3f3f3f3f3f3f;
char s[3];
void dfs(vector<ll> v1, int step)
{
    if (v1.size() == 1)
    {
        ans = min(ans, v1[0]);
        return;
    }
    vector<ll>v3;
    for(int i=0;i<v1.size();i++)
    v3.push_back(v1[i]);
    for (int i = 0; i < v1.size() - 1; i++)
    {
        for (int j = i + 1; j < v1.size(); j++)
        {
            if(s[step]=='*')
            v1.push_back(v1[i]*v1[j]);
            else
            v1.push_back(v1[i]+v1[j]);
            v1.erase(v1.begin()+i);
            v1.erase(v1.begin()+j-1);
            dfs(v1,step+1);
            while(v1.size())
            v1.pop_back();
            for(int k=0;k<v3.size();k++)
            v1.push_back(v3[k]);
        }
    }
}
int main()
{
    vector<ll> v;
    cin >> a >> b >> c >> d;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    v.push_back(d);
    cin >> s[0] >> s[1] >> s[2];
    dfs(v, 0);
    cout << ans;
    return 0;
}


活动打卡代码 AcWing 89. a^b

快速幂

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long ll;
ll a, b, p;
int get()
{
    ll ans = 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a % p;
        b >>= 1;
        a = a * a % p;
    }
    return ans % p;
}
int main()
{
    cin >> a >> b >> p;
    cout << get();
    return 0;
}


活动打卡代码 AcWing 1884. COW

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n;
int a[N];
int b[N];
char s[N];
ll ans;
int main()
{
    cin >> n;
    scanf("%s", s + 1);
    for (int i = 1; i <= n; i++)
    {
        if (s[i] == 'C')
            a[i] = 1;
        else if (s[i] == 'W')
            b[i] = 1;
    }
    for (int i = 1; i <= n; i++)
        a[i] = a[i - 1] + a[i];
    for (int i = n; i >= 1; i--)
        b[i] = b[i + 1] + b[i];
    for (int i = 1; i <= n; i++)
    {
        if (s[i] == 'O')
        {
            ans += a[i] * b[i];
        }
    }
    cout << ans;
    return 0;
}



#include <bits/stdc++.h>

using namespace std;

int a[100005];
int b[100005]; //记录区间内各个元素的个数
int n;

int ans; // 记录答案
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    int l = 1;
    for (int i = 1; i <= n; i++)
    {
        if (b[a[i]] == 0)
        {
            b[a[i]]++;
        }
        else
        {
            while (b[a[i]])
            {
                b[a[l++]]--;
            }
            b[a[i]]++;
        }
        ans = max(ans, i - l + 1); // 更新答案
    }
    cout << ans;
}


活动打卡代码 AcWing 1205. 买不到的数目

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    cout << n * m - n - m;
    return 0;
}


活动打卡代码 AcWing 717. 简单斐波那契

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a, b, c;
    a = 0, b = 1;
    for (int i = 1; i <= n; i++)
    {
        printf("%d ", a);
        c = a + b;
        a = b;
        b = c;
    }

    return 0;
}