9.14考试总结

9.14考试总结

感觉考试范围逐渐偏离自己能力范围。所以要加紧学习

小朋友的数字

DP题目,显示最大子串和,再是直接暴力

主要注意可能会爆long long;所以要理性分析

简单的推理就可以知道这个是单调上升或者下降的,所以只要判断与第一个数据的大小关系就可以推出最后结尾的答案

#include<bits/stdc++.h>
#define IL inline
#define open(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);
#define ll long long
#define ull unsigned long long
using namespace std;

ll n, p;
ll a[1000010], b[1000010];
bool pd;

IL int read();

int main()
{
//  open("number");
    n = read(); p = read();
    for (int i=1; i<=n; ++i)
    {
        a[i] = read();
        a[i] = max(a[i], a[i-1]+a[i]);
    }
    for (int i=2; i<=n; ++i)
        a[i] = max(a[i], a[i-1]);
    b[1] = a[1];
    b[2] = b[1] + a[1];
    pd = 0;
    for (int i=3; i<=n; ++i)
    {
        b[i] = b[i-1];
        if (a[i-1] > 0)
            b[i] += a[i-1];
        if (b[i] > b[1])
            pd = 1;
        if (pd) b[i] %= p;
    }
    if (pd)
        cout << b[n]%p << endl;
    else cout << b[1]%p << endl;
    return 0;
}

int read()
{
    int i = 0, j = 1;
    char x = getchar();
    while (x < '0' || '9' < x)
    {
        if (x == '-') j = -1;
        x = getchar();
    }
    while ('0' <= x && x <= '9')
    {
        i = i * 10 + x - '0';
        x = getchar();
    }
    return i*j;
}

车站分级

好像牵涉到拓扑排序(未学暂不处理)

求和

部分分方法就是枚举开始点和结束点

满分必须要分析数学原理,变成o(n)算法

#include<bits/stdc++.h>
#define IL inline
#define open(s) freopen(s".in", "r", stdin);// freopen(s".out", "w", stdout);
#define ll long long
#define ull unsigned long long
using namespace std;

int n, m;
int s[100005][2], sum[100005][2], c[100005], x[100005], ans;

IL int read();

int main()
{
//  open("sum5");
    n = read(); m = read();
    for (int i=1;i<=n;i++)
        scanf ("%d",&x[i]);
    for (int i=1;i<=n;i++)
    {
        scanf ("%d",&c[i]);
        s[c[i]][i%2]++;//姹傚嚭杩欎釜鍒嗙粍涓湁澶氬皯涓暟
        sum[c[i]][i%2] = (sum[c[i]][i%2] + x[i])%10007;
    }
    for (int i=1;i<=n;i++)
        ans = (ans + i * ((s[c[i]][i%2]-2) * x[i] % 10007 + sum[c[i]][i%2])) % 10007;
    printf ("%d\n",ans);//鏈€鍚庤緭鍑?
    return 0;
}

int read()
{
    int i = 0, j = 1;
    char x = getchar();
    while (x < '0' || '9' < x)
    {
        if (x == '-') j = -1;
        x = getchar();
    }
    while ('0' <= x && x <= '9')
    {
        i = i * 10 + x - '0';
        x = getchar();
    }
    return i*j;
}

推销员

贪心水体,因为数据比较水,怎么样都可以过

就没有放代码的意义可能是错的

猜你喜欢

转载自www.cnblogs.com/rendex/p/9649004.html