Codeforces Round 909 (Div. 3)

Codeforces Round 909 (Div. 3)

A

莫3为0必败,其他必胜

#include <bits/stdc++.h>

using namespace std;

void solve()
{
    int n;
    cin >> n;
    if(n%3==0){
        cout << "Second\n";
    }else{
        cout << "First\n";
    }
}

int main()
{
    int T;
    cin >> T;
    while(T --){
        solve();
    }
}

B

求约数,然后模拟

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;
long long a[N], s[N];

vector<int> get_divisors(int x)
{
    vector<int> res;
    for (int i = 1; i <= x / i; i++)
        if (x % i == 0)
        {
            res.push_back(i);
            if (i != x / i)
                res.push_back(x / i);
        }
    sort(res.begin(), res.end());
    return res;
}

void solve()
{
    long long n, maxn = -0x3f3f3f3f, minn = 0x3f3f3f3f , ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }
    vector<int> res = get_divisors(n);
    for (auto x : res)
    {
        if(x == n)continue;
        maxn = -0x3f3f3f3f3f3f3f3f, minn = 0x3f3f3f3f3f3f3f3f;
        for(int i = x; i <= n ; i += x){
            minn = min(minn , s[i] - s[i - x]);
            maxn = max(maxn , s[i] - s[i - x]);
        }
        ans = max(ans , maxn - minn);
    }
    cout << ans << endl;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
}

C

dp,dp[i]表示到第i个的最大值,可由第i个选或不选得到

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;
int INF = 0x3f3f3f3f;
long long a[N], dp[N];

bool check(long long x , long long y){
    if(x&1){
        if(y&1)return false;
        else return true;
    }else{
        if(y&1)return true;
        else return false;
    }
    return 0;
}

void solve()
{
    long long n , ans = -INF;
    cin >> n;
    for(int i = 1 ; i <= n ; i ++){
        cin >> a[i];
    }
    dp[1] = a[1];
    for(int i = 2 ; i <= n ; i ++){
        dp[i] = a[i];
        if(check(a[i] , a[i - 1])){
            dp[i] = max(dp[i] , dp[i-1] + a[i]);
        }
    }
    for(int i = 1 ; i <= n ; i ++){
        ans = max(ans , dp[i]);
    }
    cout << ans << endl;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
}

D

只有当i,j为1,2或者i=j时成立,统计

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;
int INF = 0x3f3f3f3f;
long long a[N], dp[N];

void solve()
{
    long long n , ans = 0;
    cin >> n;
    map<int,int> m;
    for(int i = 1 ; i <= n ; i ++){
        cin >> a[i];
        ans += m[a[i]] ++;
    }
    ans += 1LL * m[1] * m[2];
    cout << ans << endl;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
}

E

数列第一次出现最小值后一直都是最小值,因此最小值最后的数必须有序否者返回-1,有序则返回第一次出现最小值的位置

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;
int INF = 0x3f3f3f3f;
long long a[N], dp[N];

void solve()
{
    long long n , ans = 0 , minn = INF , idx = -1;
    cin >> n;
    for(int i = 0 ; i < n ; i ++){
        cin >> a[i];
        if(a[i] < minn){
            minn = a[i];
            idx = i;
        }
    }
    bool f = true;
    for(int i = idx ; i + 1 < n ; i ++){
        if(a[i] > a[i + 1])f = false;
    }
    if(f){
        cout << idx << endl;
    }else{
        cout << "-1\n";
    }
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
}

F

一开始构造一条链,,每次通过移动点 n 的位置来保证条件

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;
int INF = 0x3f3f3f3f;
long long a[N], dp[N];

void solve()
{
    long long n , q;
    cin >> n >> q;
    int p = n-1;
    for (int i = 1; i < n; ++i) cout << i << ' ' << i + 1 << "\n";
    for (int i = 1, d; i <= q; ++i) {
        cin >> d;
        if(p == d) cout << "-1 -1 -1\n";
        else {cout << n << ' ' << p << ' ' << d << "\n"; p = d;}
    }
    return ;
}

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        solve();
    }
}

  • 15
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值