zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 103 (Rated for Div. 2)部分题解

    Problem A

    并不知道我为什么wa2的原因是什么..大概就是分情况讨论,当n和k相等时很明显就是1,当n>k时很明显答案就是二,那么n<k的时候,我们算出一共需要多少的数量,然后一排排放,算一下是否整除就行。

    Problem B

    让我们为维护一个通货膨胀率,那么很容易我们可以看得出,所有的钱都加在初始资金上一定最优,那么我们去维护前缀和,过程中去check和修改金额就可以了,当然这题需要开ll,不然会wa3.

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> PII;
    const int maxn=1e3+10;
    ll a[maxn];
    ll c[maxn];
    
    int main () {
        int t; scanf ("%d",&t);
        while (t--) {
            int n,k; scanf ("%d%d",&n,&k);
            double st=k*1.0/100;
            ll ans=0;
            for (int i=1;i<=n;i++) {
                scanf ("%lld",&a[i]);
                if (i>=2) {
                    double now=a[i]*1.0/c[i-1];
                    if (now>st) {
                        ll need=ceil ((a[i]*100.0)/k)*1ll;
                        ll add=need-c[i-1];
                        c[i-1]+=add;
                        ans+=add;
                    }
                }
                c[i]=c[i-1]+a[i];
            }
            printf ("%lld
    ",ans);
        }
        return 0;
    }   
    

    Problem C

    我们在过程中维护最大左子环就行,简单分情况讨论一下,过程中取最大值就行。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    void check_max (ll &a,ll b) {a=max (a,b);}
    void check_min (int &a,int b) {a=min (a,b);}
    typedef pair<int,int> PII;
    const int maxn=1e5+10;
    ll a[maxn],cnt,ans;
    ll c[maxn];
    ll b[maxn];
    
    int main () {
        int t; scanf ("%d",&t);
        while (t--) {
            cnt=0;
            ans=0;
            int n; scanf ("%d",&n);
            for (int i=1;i<=n;i++) scanf ("%lld",&c[i]);
            for (int i=1;i<=n;i++) scanf ("%lld",&a[i]);
            for (int i=1;i<=n;i++) {
                scanf ("%d",&b[i]);
                if  (i==2) cnt=1ll*abs (a[i]-b[i])+1;
                else if (i>2) {
                    if (a[i]==b[i]) cnt=1;
                    else {
                        cnt=max (1ll*abs (a[i]-b[i])+1,
                                cnt+c[i-1]-1ll*abs (a[i]-b[i])+1);
                    }
                }
                if (i>=2) check_max (ans,cnt+c[i]);
            }
            printf ("%lld
    ",ans);
        }
        return 0;
    }   
    
  • 相关阅读:
    Oracle数据库管理
    Oracle——范式
    GUID
    java课上知识点整理—语句
    java课上知识点整理—java代码结构、标识符、数据类型、运算符
    使用css实现时间轴
    超简单的轮播实现
    第一个vue示例-高仿微信
    12. thymeleaf中资源相对路径的解决
    11. 将博客部署到tomcat上
  • 原文地址:https://www.cnblogs.com/hhlya/p/14350947.html
Copyright © 2011-2022 走看看