AtCoder Beginner Contest 153 [A - F]

Keywords: less REST

Title Source: https://atcoder.jp/contests/abc153

Winter vacation was so decadent that I didn't write a question all the time. Then I almost mistook the second question. And the last question at that time, I would not But if I make up the difference and learn some skills, I will score up if I play that game

A - Serval vs Monster

Water problem

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    r(n); r(m);
    int ans=n/m;
    if(n%m!=0) ans++;
    cout<<ans<<endl;
    return 0;
}

B - Common Raccoon vs Monster

It's a shame that I read this question wrong
Is to subtract all to see if it is less than or equal to 0

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    r(n); r(m);
    while(m--){
        int a; r(a);
        n-=a;
    }
    if(n<=0) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

C - Fennec vs Monster

It's just a greedy question. Drop the most blood in the first second, and add up the rest

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
int f[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    r(n); r(m);
    LL ans=0;
    FOR(i,1,n){
        r(f[i]);
    }
    sort(f+1,f+n+1);
    FOR(i,1,n-m){
        ans+=f[i];
    }
    cout<<ans<<endl;
    return 0;
}

D - Caracal vs Monster

There is a formula for this problem
h=1 1 attack [1 = 21-1]
H = 21 attacks split into 2 h=1 attacks twice [1 + 2 = 22-1]
h=3 is the same as 2 [1 + 2 = 22-1]
H = 41 attacks split into 2 h=2 attacks split into 4 h=1 attacks split into 4 [1 + 2 + 4 = 23-1]
And the index is log2(h)+1

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
LL f[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    r(n);
    f[0]=1;
    FOR(i,1,60){
       f[i]=f[i-1]*2;
    }
    FOR(i,0,60){
        if(n<f[i]){
            cout<<f[i]-1<<endl;
            break;
        }
    }
    return 0;
}


E - Crested Ibis vs Monster

I wrote this question with DP, it's very comfortable
This can be understood as the knapsack problem. Each item can be taken countless times. The weight is a, the cost is b, and the cost should be minimized.
But it's not the same. It's changed. We make DP [i] represent the minimum cost to achieve weight I
Then the final answer should be the minimum of DP [H] and DP [H + 1E4]
Note that it is not DP [H] to DP [2 * H] that may cost a little but weigh much more than H

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
int f[N];
int dp[N];
int w[N],v[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    r(m); r(n);
    FOR(i,1,n){
        r(v[i]);
        r(w[i]);
    }
    FOR(i,1,m+1e4) dp[i]=2e9;
    dp[0]=0;
    FOR(i,1,n){
        for(int j=v[i];j<=m+1e4;j++){
//            cout<<i<<' '<<j<<' '<<dp[j-v[i]]+w[i]<<endl;
            dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
        }
    }
    int ans=2e9;
    FOR(i,m,m+1e4){
        ans=min(dp[i],ans);
    }
    cout<<ans<<endl;
    return 0;
}


F - Silver Fox vs Monster

I did get the difference skill in the last question
First of all, this problem needs to find the leftmost coordinate l every time, and then every operation is to take [L + 2 * D], which is a greedy idea
How to find monsters in this area? We can find the monster coordinate r at the far right of the range in two points
But how to make all monsters in this range lose blood? Difference!
For example, if you want [l, R] to subtract T, you can roll a prefix and let Q [l] - = t, Q [R + 1] + = t
Then loop q[l]+=q[l-1] to reduce t

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
struct node
{
    int x,v;
}f[N];
LL sum[N];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    int a;
    rrr(n,m,a);
    FOR(i,1,n){
        r(f[i].x); r(f[i].v);
    }
    sort(f+1,f+n+1,cmp);
    LL now=0;
    LL ans=0;
    FOR(i,1,n){
        sum[i]+=sum[i-1];
        f[i].v+=sum[i];
        if(f[i].v<=0) continue;
        int l=i,r=n,res;
        while(l<=r){
            int mid=(l+r)>>1;
            if(f[mid].x<=f[i].x+2*m){
                res=mid;
                l=mid+1;
            }
            else r=mid-1;
        }
        //I -- ans-
        int t=f[i].v/a;
        if(f[i].v%a) t++;
        ans+=t;
        sum[i]-=t*a;
        sum[res+1]+=t*a;
    }
    cout<<ans<<endl;
    return 0;
}

When can I get rid of AK ABC, 555

63 original articles published, 82 praised, 5808 visited
Private letter follow

Posted by sametch on Sat, 01 Feb 2020 21:49:17 -0800