【遊記】CSP J/S 2019 遊記

J 組

\(2:30\)開始, \(2:13\)還在酒店的我看了看手錶。。。飛奔考場。ios

T1 數字遊戲

秒切。spa

下午某中學某大佬說可用線性基(%)code

T2 公交換乘

用單調隊列思想,秒切。隊列

T3 記念品

剛看題,wow這不水題嗎,鐵定\(DP\),再看,嗯?啥時候買?啥時候賣?。。。後來發現可用揹包,感受正解,樣例2沒過。。。遊戲

考場代碼:string

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long

using namespace std;

const int N = 110;
 
int t, n;
ll m, ans;
ll a[N][N];
bool f[200010];
ll  b[200010][N];

int main()
{
    freopen("souvenir.in", "r", stdin);
    freopen("souvenir.out", "w", stdout);
    scanf("%d%d%lld", &t, &n, &m);
    for (int i = 1; i <= t; i++)
        for (int j = 1; j <= n; j++)
            scanf("%lld", &a[i][j]);
    for (int i = 1; i < t; i++)
    {
        memset(f, 0, sizeof(f));
        memset(b, 0, sizeof(b));
        f[0] = 1;
        for (int j = 1; j <= n; j++)
        {
            if(a[i][j] < a[i + 1][j])
            {
                for (int k = a[i][j]; k <= m; k++)
                {
                    f[k] = f[k] || f[k - a[i][j]];
                    if(f[k - a[i][j]])
                        b[k][j] += b[k - a[i][j]][j] + 1;
                }
            }
        }
        ll plu = -22222;
        for (int j = m; j > 0; j--)
        {
            if(f[j])
            {
                plu = m - j;
                for (int k = 1; k <= n; k++)
                    if(b[j][k])
                    plu += m / (b[j][k] * a[i][k]) * (b[j][k] * a[i + 1][k]);
                break;
            }
        }
        if(plu != -22222)m = plu;
    }
    printf("%lld", m);
    return 0;
}

正解:it

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long

using namespace std;

const int N = 110;
 
int t, n;
ll m, ans;
ll a[N][N];
ll f[200010];

int main()
{
    freopen("souvenir.in", "r", stdin);
    freopen("souvenir.out", "w", stdout);
    scanf("%d%d%lld", &t, &n, &m);
    for (int i = 1; i <= t; i++)
        for (int j = 1; j <= n; j++)
            scanf("%lld", &a[i][j]);
    for (int i = 1; i < t; i++)
    {
        memset(f, 0, sizeof(f));
        
        for (int j = 1; j <= n; j++)
        {
            for (int k = a[i][j]; k <= m; k++)
            {
                f[k] = max(f[k], f[k - a[i][j]] + a[i + 1][j] - a[i][j]);
            }
        }
        m = max(m, f[m] + m);
    }
    printf("%lld", m);
    return 0;
}

。。。io

我枯了class

T4 加工零件

考場想到了最短路,但發現不對勁,打了個\(\texttt{BFS}\)暴力。stream

正解:最短路

。。。

S組

Day0

\(\text{上午:}\)學校運動會,偷溜至機房。
\(\text{下午:}\)去廣州

Day1

T1

\[\Large\text{十年OI一場空,不開unsigned見祖宗}\]

相關文章
相關標籤/搜索