zoukankan      html  css  js  c++  java
  • Education CodeForces Round 63 Div.2

    A. Reverse a Substring

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    int N;
    string s;
    
    int main() {
        scanf("%d", &N);
        cin >> s;
    
        int temp = -1;
        for(int i = 1; s[i]; i ++) {
            if(s[i] < s[i - 1]) {
                temp = i;
                break;
            }
        }
    
        if(temp == -1) printf("NO
    ");
        else {
            printf("YES
    ");
            temp += 1;
            printf("%d %d
    ", temp - 1, temp);
        }
    
        return 0;
    }
    View Code

    B. Game with Telephone Numbers

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    int N;
    int eight = 0;
    string s;
    
    int main() {
        scanf("%d", &N);
        cin >> s;
        bool flag = true;
        for(int i = 0; i <= N - 11; i ++) {
            if(s[i] == '8')
                eight ++;
        }
        if(eight <= ((N - 11) / 2)) flag = false;
    
        if(flag) printf("YES
    ");
        else printf("NO
    ");
    
        return 0;
    }
    View Code

    C. Alarm Clocks Everywhere

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 3e5 + 10;
    int N, M;
    long long a[maxn], p[maxn], b[maxn];
    
    long long gcd(long long a, long long b) {
        return b == 0 ? a : gcd(b, a % b);
    }
    
    int main() {
        scanf("%d%d", &N, &M);
        long long t;
        for(int i = 1; i <= N; i ++) {
            cin >> a[i];
            //scanf("%lld", &a[i]);
            if(i == 1) b[i] = 0;
            else b[i] = a[i] - a[i - 1];
        }
    
        for(int i = 2; i <= N; i ++) {
            if(i == 2) t = b[i];
            else t = gcd(t, b[i]);
        }
    
        bool flag = false;
        int temp;
        for(int i = 1; i <= M; i ++) {
            cin >> p[i];
            //scanf("%lld", &p[i]);
            if(t % p[i] == 0) {
                temp = i;
                flag = true;
            }
        }
    
        int ansp = temp;
        if(!flag) printf("NO
    ");
        else {
            printf("YES
    ");
            cout << a[1] << " " << ansp << endl;
        }
    
        return 0;
    }
    View Code

    D. Beautiful Array

    代码:(D 神仙 dp 自己写了贪心 但是不对有一些情况不可以 枯了 )

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 3e5 + 10;
    long long a[maxn], dp[maxn][5];
    int N, K;
    
    int main() {
        memset(dp, -1e18, sizeof(dp));
        scanf("%d%d", &N, &K);
        long long ans = 0;
        for(int i = 1; i <= N; i ++) {
            cin >> a[i];
            dp[i][0] = max(dp[i - 1][0], 0LL) + a[i];
            dp[i][1] = max(max(dp[i - 1][1], dp[i - 1][0]), 0LL) + 1LL * K * a[i];
            dp[i][2] = max(max(max(dp[i - 1][1], dp[i - 1][0]), dp[i - 1][2]), 0LL) + a[i];
            ans = max(ans, max(dp[i][0], max(dp[i][1], dp[i][2])));
        }
        cout << ans << endl;
        return 0;
    }
    View Code

     

  • 相关阅读:
    java连接oracle
    用js实现登录的简单验证
    合并链表,按主键升序
    Jquery中.ajax和.post详解
    简洁的Jquery弹出窗插件
    服务端缓存页面及IIS缓存设置
    C#托管代码、非托管代码及回收机制
    页面滑动底部自动加载下一页信息
    EF各版本增删查改及执行Sql语句
    Node.Js and Mongoose
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/10762030.html
Copyright © 2011-2022 走看看