Educational Codeforces Round 95 (Rated for Div. 2) A-D

A

计算出总的stick数目tot, ⌈(tot-1)/(k-1)⌉即可
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define lowbit(i) ((-i) & (i))
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define int long long

template<class T>void read(T &x)
{
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}

#define ull unsigned long long
#define eps 1e-12
#define sc(x) scanf("%lld", &(x))
#define mem(a,b) memset(a,b,sizeof(a))
#define endl "\n"
#define inf 0x3f3f3f3f
#define ll long long
#define dbug cout<<"here\n";
#define int long long

const int mod = 1e9+7;
const int maxn=5e5+10;

int n;
void work()
{
    int x,y,k;
    cin>>x>>y>>k;
    int ans=0;
    ans+=k;
    int tot=0;
    tot+=k*y+k;
    ans+=(tot-1 +x-1-1)/(x-1);
    cout<<ans<<endl;
}
signed main()
{
    int t;cin>>t;
    while(t--)
    work();
}

B

对于不固定的数,从小到大排序即可
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define lowbit(i) ((-i) & (i))
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define int long long

template<class T>void read(T &x)
{
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}

#define ull unsigned long long
#define eps 1e-12
#define sc(x) scanf("%lld", &(x))
#define mem(a,b) memset(a,b,sizeof(a))
#define endl "\n"
#define inf 0x3f3f3f3f
#define ll long long
#define dbug cout<<"here\n";
#define int long long

const int mod = 1e9+7;
const int maxn=5e5+10;


int cmp(int a,int b)
{
    return a>b;
}

int n;
int arr[maxn],vis[maxn];
int a[maxn],b[maxn];
int p[maxn];
void work()
{
    read(n);
    rep(i,1,n) read(arr[i]);
    rep(i,1,n) read(vis[i]);
    int la=0,lb=0;
    rep(i,1,n)
    {
        if(vis[i]==1) a[++la]=arr[i];
        else b[++lb]=arr[i];
    }
    sort(b+1,b+1+lb,cmp);
    p[0]=0;
    rep(i,1,la)
    {
        p[i]=p[i-1]+a[i];
    }
    int l=1,r=1;
    for(int i=1;i<=n;i++)
    {
        if(vis[i]) printf("%lld",arr[i]);
        else printf("%lld",b[l++]);
        printf("%c",i==n?'\n':' ');
    }
}

signed main()
{
    int t;cin>>t;
    while(t--)
    work();
}

C

二维dp[i][j]代表在第i位是由第j个玩家打boss, 转移很好推, 如代码.
ps:也可以特判第一位, 然后找[2,n]中有几个111的出现
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define lowbit(i) ((-i) & (i))
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define urep(i, x, y) for(int i=x;i>=y;i--)
template<class T>void read(T &x)
{
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}

#define ull unsigned long long
#define eps 1e-12
#define sc(x) scanf("%lld", &(x))
#define mem(a,b) memset(a,b,sizeof(a))
#define endl "\n"
#define inf 0x3f3f3f3f
#define ll long long
#define dbug cout<<"here\n";

#define int long long

const double PI = acos(-1.0);
const int mod = 1e9+7;
const int maxn=5e5+10;



void Prime(int prime[],int visit[],int ed)
{
    mem(visit,0);
    mem(prime,0);
    for (int i = 2;i <= ed; i++) {
        if (!visit[i]) {
            prime[++prime[0]] = i;
        }
        for (int j = 1; j <=prime[0] && i*prime[j] <= ed; j++) {
            visit[i*prime[j]] = 1;
            if (i % prime[j] == 0) {
                break;
            }
        }
    }
}


int prime[maxn];
int visit[maxn];



int a[maxn];
int b[maxn];

int n;

int dp[maxn][3];

void work()
{
    read(n);
    rep(i,1,n) read(a[i]);
    rep(i,1,n) dp[i][1]=dp[i][2]=inf;
    dp[0][1]=dp[0][2]=0;
    rep(i,1,n)
    {
        dp[i][1]=min(dp[i][1],dp[i-1][2]+(a[i]==1));
        if(i>=2)
        {
            dp[i][1]=min(dp[i][1],dp[i-2][2]+(a[i-1]==1)+(a[i]==1));
        }
        if(i!=1)
        {
            dp[i][2]=min(dp[i][2],dp[i-1][1]);
            if(i>=3)
            {
                dp[i][2]=min(dp[i][2],dp[i-2][1]);
            }
        }
    }
    printf("%lld\n",min(dp[n][1],dp[n][2]));
}

signed main()
{
    int t;
    read(t);
    while(t--)
        work();
}

D

用multiset,原序列q和维护差分p,ans就是max(q)-min(q)-max(p)
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define lowbit(i) ((-i) & (i))
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define urep(i, x, y) for(int i=x;i>=y;i--)
template<class T>void read(T &x)
{
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}

#define ull unsigned long long
#define eps 1e-12
#define sc(x) scanf("%lld", &(x))
#define mem(a,b) memset(a,b,sizeof(a))
#define endl "\n"
#define inf 0x3f3f3f3f
#define ll long long
#define dbug cout<<"here\n";

#define int long long

const double PI = acos(-1.0);
const int mod = 1e9+7;
const int maxn=5e5+10;



void Prime(int prime[],int visit[],int ed)
{
    mem(visit,0);
    mem(prime,0);
    for (int i = 2;i <= ed; i++) {
        if (!visit[i]) {
            prime[++prime[0]] = i;
        }
        for (int j = 1; j <=prime[0] && i*prime[j] <= ed; j++) {
            visit[i*prime[j]] = 1;
            if (i % prime[j] == 0) {
                break;
            }
        }
    }
}


int prime[maxn];
int visit[maxn];

int a[maxn];

void work()
{
    int n,m;
    read(n),read(m);
    multiset<int>q,p;
    rep(i,1,n) read(a[i]);
    sort(a+1,a+1+n);
    int ans=0;
    rep(i,1,n)
    {
        q.insert(a[i]);
        if(i>1)
        {
            ans+=a[i]-a[i-1];
            p.insert(a[i]-a[i-1]);
        }
    }
    if(p.size()>=1)
        cout<<ans-*(--p.end())<<endl;
    else cout<<ans<<endl;
    while(m--)
    {
        int cmd,val;
        read(cmd),read(val);
        if(cmd==1)
        {
            if(q.empty())
            {
                q.insert(val);
            }
            else
            {
                auto l=q.lower_bound(val);
                auto r=q.upper_bound(val);
                if(val > *(--q.end()))
                {
                    p.insert(val - *(--q.end()));
                    ans+=val - *(--q.end());
                }
                else if(val < *q.begin())
                {
                    p.insert(*q.begin() - val);
                    ans+=*q.begin()-val;
                }
                else
                {
                    --l;
                    int del=*r-*l;
                    p.erase(p.lower_bound(del));
                    p.insert(*r-val);
                    p.insert(val-*l);
                }
                q.insert(val);
            }
        }
        else
        {

            auto pos=q.lower_bound(val);
            if(val==*q.begin())
            {
                int temp;
                if(q.size() > 1)
                {
                    temp=*(++q.begin())-*q.begin();
                    p.erase(p.lower_bound(temp));
                    ans-=temp;
                }
                q.erase(q.lower_bound(val));
            }
            else if(val==(*--q.end()))
            {
                if(q.size() > 1)
                {

                    int temp=*(--q.end()) - *(--(--q.end()));
                    p.erase(p.lower_bound(temp));
                    ans-=temp;
                }
                q.erase(q.lower_bound(val));
            }
            else
            {
                auto l = --pos;
                auto r = ++(++pos);
                pos--;
                p.erase(p.lower_bound(*r-*pos));
                p.erase(p.lower_bound(*pos-*l));
                p.insert(*r-*l);

                q.erase(q.lower_bound(val));
            }
        }


        if(p.size() >= 1)
            cout<<ans-*(--p.end())<<endl;
        else cout<<ans<<endl;
    }

}

signed main()
{

        work();
}


posted @ 2020-09-16 11:12  Minun  阅读(121)  评论(0编辑  收藏  举报