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();
    }
}

相关推荐

  1. Codeforces Round 909 (Div. 3)

    2023-12-10 20:08:03       42 阅读
  2. Codeforces Round 900 (Div. 3)补题

    2023-12-10 20:08:03       49 阅读
  3. codeforce#939 (div2) 题解

    2023-12-10 20:08:03       25 阅读
  4. cf-913-div3

    2023-12-10 20:08:03       37 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-10 20:08:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-10 20:08:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-10 20:08:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-10 20:08:03       20 阅读

热门阅读

  1. 名字的漂亮度

    2023-12-10 20:08:03       33 阅读
  2. 【前端设计模式】之原型模式

    2023-12-10 20:08:03       34 阅读
  3. LeetCode452. Minimum Number of Arrows to Burst Balloons

    2023-12-10 20:08:03       34 阅读
  4. TCP一对一聊天

    2023-12-10 20:08:03       46 阅读
  5. 清理oracle库30亿的表后,释放删除空间

    2023-12-10 20:08:03       29 阅读
  6. MySQL、Oracle笔记

    2023-12-10 20:08:03       31 阅读
  7. vue中滚轮缩放事件

    2023-12-10 20:08:03       36 阅读
  8. axios封装、二次封装

    2023-12-10 20:08:03       42 阅读
  9. 网络视频服务器的作用是什么?

    2023-12-10 20:08:03       42 阅读
  10. TCP聊天

    TCP聊天

    2023-12-10 20:08:03      29 阅读
  11. STM32用flash保存参数实现平衡擦写的一种方法

    2023-12-10 20:08:03       31 阅读
  12. 三元组的快速转置(数据结构实训)

    2023-12-10 20:08:03       31 阅读
  13. MyBatis-xml版本

    2023-12-10 20:08:03       43 阅读