洛谷《深入浅出》进阶篇 空间换时间

空间换时间

题目一:直播获奖 ( P 7072 ) (P7072) (P7072)

P7072 [CSP-J2020] 直播获奖

/*
coder:sunshine
school:njupt
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n' //交互题删掉
#define x first
#define y second
typedef long long ll;
typedef pair<int, int> PII;
const int mod = 1e9 + 7;

const int N = 610;
int a[N], n, w;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> w;
    for (int i = 1; i <= n; i++)
    {
        int tmp;
        cin >> tmp;
        a[tmp]++;
        int sum = 0;
        for (int j = 600; j >= 0; j--)
        {
            sum += a[j];
            if (sum >= max(1, i * w / 100))
            {
                cout << j << ' ';
                break;
            }
        }
    }
    return 0;
}

题目二:求和 ( P 2671 ) (P2671) (P2671)

P2671 [NOIP2015 普及组] 求和

/*
coder:sunshine
school:njupt
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n' //交互题删掉
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 10007;

constexpr int N = 1e5 + 10;
int n, m;
int a[N], b[N];
int s1[N][2], s2[N][2];
int ans;

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> b[i];
        s1[b[i]][i % 2]++;
        s2[b[i]][i % 2] = (s2[b[i]][i % 2] + a[i]) % mod;
    }
    for (int i = 1; i <= n; i++)
    {
        int y = b[i];
        ans += i * (s2[y][i % 2] + a[i] * (s1[y][i % 2] - 2) % mod) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

题目三:玉蟾宫 ( P 4147 ) (P4147) (P4147)

P4147 玉蟾宫

/*
coder:sunshine
school:njupt
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n' //交互题删掉
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;

constexpr int N = 1010;
int n, m, ans = 0;
char a[N][N];
int h[N][N], l[N][N], r[N][N];
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> a[i][j];
            h[i][j] = 1;
            r[i][j] = l[i][j] = j;
        }
        for (int j = 2; j <= m; j++)
        {
            if (a[i][j] == 'F' && a[i][j - 1] == 'F')
            {
                l[i][j] = l[i][j - 1];
            }
        }
        for (int j = m - 1; j > 0; j--)
        {
            if (a[i][j] == 'F' && a[i][j + 1] == 'F')
            {
                r[i][j] = r[i][j + 1];
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (i > 1 && a[i][j] == 'F')
            {
                if (a[i - 1][j] == 'F')
                {
                    h[i][j] = h[i - 1][j] + 1;
                    if (l[i - 1][j] > l[i][j])
                    {
                        l[i][j] = l[i - 1][j];
                    }
                    if (r[i - 1][j] < r[i][j])
                    {
                        r[i][j] = r[i - 1][j];
                    }
                    if ((r[i][j] - l[i][j] + 1) * h[i][j] > ans)
                    {
                        ans = (r[i][j] - l[i][j] + 1) * h[i][j];
                    }
                }
            }
        }
    }
    cout << 3 * ans << endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值