A. Maximize The Beautiful Value

戳我传送

Solution

题目大意是把一个数往前挪至少k位,i到i-k数往后挪,因为这是个非递减数列,要求

图片说明 最大 ,显然后面的权值大于前面,所以只要把一个数往前移动k位即可,之间的数往后挪动因此用前缀和加上sum[i - 1] - sum[i - 1 - k]即可

code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e8
const int mod = 1e9+7;
const int maxn = 1e5+7;
#define iss ios::sync_with_stdio(false)
 inline int read() {
    int s = 0, w = 1; char ch = getchar();
    while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }
    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return s * w;
}
ll a[maxn],sum[maxn];
 int main() {
    int T = read();
    while (T--) {
        int n = read(), k = read();
        ll res = 0;
        for (int i = 1; i <= n; ++i) {
            a[i] = read();res += a[i] * i;
            sum[i] = sum[i - 1] + a[i];
        }
        ll ans = 0;
        for (int i = k + 1; i <= n; ++i) {
            ans = max(ans,res + (sum[i - 1] - sum[i - 1 - k]) - a[i] * k);
        }
        printf("%lld\n", ans);
    }
}

B. 身体训练

戳我传送

Solution

题目大意是n个人排成一列,间距为u,初始速度为v,最后面的人以 c [ i ]的速度跑到第一个人前u米,然后现在最后一个人再以c[ i ]跑,每过一轮每个人的最大速度衰减 d[ i ] 题目保证速度不会低于v,因此完全可以看成每个人开始是静止的即速度为c[ i ] - v,要跑的距离为 n * u,所得时间相加除 n 即可。

code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e8
const int mod = 1e9+7;
const int maxn = 10005;
#define iss ios::sync_with_stdio(false)
inline ll read(){
    ll s = 0, w = 1; char ch = getchar();
    while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }
    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return s * w;
}
int main(){
    int n;
    double u,v;
    double c[1005],d[1005];
    cin>>n>>v>>u;
    for(int i = 0 ; i < n ;++i){
        cin>>c[i];c[i] -= v;
    }
    for(int i = 0 ; i < n ;++i) cin>>d[i];
    double t = 0,ans = 0,jj = 0;
    for(int i = 0 ; i < n ;++i){
        for(int j = 0 ; j < n ; ++j) t += u/c[j];
        ans += t;t = 0;
        for(int j = 0 ; j < n ; ++j) c[j]-=d[j];
    }
    cout<<fixed<<setprecision(3)<<ans<<endl;
}

E. 幸运数字Ⅱ

戳我传送

Solution

用dfs模拟出所有的4 7 序即可

code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e8
const int mod = 1e9+7;
const int maxn = 10005;
#define iss ios::sync_with_stdio(false)
inline ll read(){
    ll s = 0, w = 1; char ch = getchar();
    while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }
    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return s * w;
}
vector<ll> q;
void dfs(ll x){
    if(x>1e9) return ;
    q.push_back((x<<3)+(x<<1)+4);//左移三为x*8,左移1为x*2,和就是x*10,听说这样更快(LS大佬教的)
     dfs((x<<3)+(x<<1)+4);
    dfs( (x<<3)+(x<<1)+7);
    q.push_back( (x<<3)+(x<<1)+7);
}
int main(){
    dfs(0);
    sort(q.begin(),q.end());
    q.push_back(4444444444);//注意范围
    ll l,r;
    cin>>l>>r;
    ll pos = 0,ans = 0;
    while(l<=r){
        if(q[pos]>=l&&q[pos]<=r){
            ans += (q[pos]-l+1)*q[pos];
            l = q[pos]+1;
        }
        if(q[pos]>r){
            ans += q[pos]*(r-l+1);
            break;
        }
        ++pos;
    }
    cout<<ans<<endl;
}