题解

· · 题解

游戏

本题是一个简单的数学问题,注意卡double 代码如下

#include<bits/stdc++.h>
using namespace std;
string s;
long long ans;
long long a,b,c,d,e;
int main(){
    int T;scanf("%d",&T);
    while(T--){
        cin>>s;
        cin>>a>>b>>c>>d>>e;
        if(s[0]=='W'){
            ans=(d*1e6-b*(1e4+min(100ll,c)*(100+2*c))*(100-e));
        }
        else{
            ans=(d*100-b*(100-1*e))*1e4;
        }
        printf("%lld\n",ans);
    }
} 

数列

本题是一道贪心。

易发现优美序列是一个长度为m,满足l,r限制,并且不能是参考数列的子序列。

观察到m值比较小,可以考虑遍历序列lr来“查找”是否能得到优美序列。

如果能够在枚举的当前位尽可能地让该数字在参考序列中靠后,直到枚举到某一位,参考序列中没有该位上的数字,则可以说明得到的序列是优美的

附上代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
string s,L,R;
int a[10];
int List[330][20];
int vis[20][10];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> s;
    m = s.size();
    cin >> n;
    cin >> L >> R;
    for (int i = 0; i <= 9; i++) a[i] = 2e9;
    for (int i = m; i >= 0; i--) {
        for (int j = 0; j <= 9; j++) List[i][j] = a[j];
        if (i >= 1)
        a[s[i - 1] - '0'] = i;
    }
    int pos = 0;
    for (int i = 1; i <= n; i++) {
        int Max = -2e9;
        for (int j = L[i - 1] - '0'; j <= R[i - 1] - '0'; j++) {
            Max = max(Max, List[pos][j]);
        }
        if (Max > m) {
            cout << "YES\n";
            return 0;
        } else pos = Max;
    }
    cout << "NO\n";
    return 0;
}