Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)

Codeforces Round #623 (Div. 2, based on VK Cup 2019-2020 - Elimination Round, Engine)

A题:

在这里插入图片描述
思路如图所示,我们的正方形面积一定在其中产生。写的时候注意判一下边界就行了。

#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+7;
int a,b;
int getare(int x1,int y1,int x2,int y2)
{
    if(x1<0||x1>=a||y1>=b||y1<0||x2<0||x2>=a||y2>=b||y2<0) return 0;
//    cout<<(abs(x1-x2)+1)*(abs(y1-y2)+1)<<endl/;
    return (abs(x1-x2)+1)*(abs(y1-y2)+1);
}
int main()
{
    int  t; cin>>t;
    while(t--) {
        int x, y; cin>>a>>b>>x>>y;
        int res=0;
        res=max(res,getare(0,0,a-1,y-1));
        res=max(res,getare(0,y+1,a-1,b-1));
        res=max(res,getare(0,0,x-1,b-1));
        res=max(res,getare(x+1,0,a-1,b-1));
        cout<<res<<endl;
    }
}

B题:

阅读题。我们倒着求费用,如果能做交通工具,就做交通工具,否则就是走路。

#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int N=1e5+7;
int a,b;
int main()
{
    int t; scanf("%d",&t);
    while(t--){
        int a,b,p; scanf("%d%d%d",&a,&b,&p);
        string s; cin>>s;
        int len=s.length()-2,i;
        for(i=len;i>=0;i--){
            if(s[i]=='A'){
                if(p<a){
                    break;
                }
                p-=a;
            }else if(s[i]=='B'){
                if(p<b){
                    break;
                }
                p-=b;
            }
            while(i>0&&s[i]==s[i-1]) i--;
        }
        cout<<i+2<<endl;
    }
}

C题:

每个元素一定是不一样的。所以利用set的删除,查找功能会很方便。

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e2+10;
int n, a[maxn], b[maxn];
set<int> s;
int main()
{
    int T ; cin>>T;
    while(T--)
    {
        s.clear();
        cin>>n;
        for(int i = 1; i <= n*2; i++) s.insert(i);
        for(int i = 1; i <= n; i++) cin>>b[i],s.erase(b[i]);
        int flag = 1;
        for(int i = 1; i <= n; i++)
        {
            a[i*2-1] = b[i];
            auto p = s.lower_bound(b[i]);
            if(p == s.end())
            {
                flag = 0;
                break;
            }
            a[i*2] = *p;
            s.erase(a[i*2]);
        }
        if(flag) for(int i = 1; i <= n*2; i++) printf("%d ", a[i]);
        if(!flag) printf("-1");
        putchar(10);
    }
    return 0;
}
 

D题:

让每本书的个数都不一样的最小代价花费。我们的切入口是:我们没办法保证我们增加了某些书的个数之后不和其他种类的书的个数相同。所以我们考虑一些相同本数的书但种类不同的一个集合,用mulset维护,我们同一个集合中为了尽可能的减少花费,我们肯定除了最贵的那本书不增加,而增加其他的书就可以了。这样一定能保证我们的代价是最小的。然后分析复杂度,每本数最多进出一次,进来就是log,那就是nlog这道题足够了。

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5+10;
multiset<int> st;
pair<int,int> pp[N];
signed main()
{
    int n; cin>>n;
    for(int i=1;i<=n;i++) cin>>pp[i].first;
    for(int i=1;i<=n;i++) cin>>pp[i].second;
    sort(pp+1,pp+1+n);
    int book_num=-1,ans=0,sum=0;
    for(int i=1;i<=n;i++){
        while(st.size()&&book_num<pp[i].first){
            int mx=*st.rbegin();
            ans+=sum-mx;
            sum-=mx;
            st.erase(st.find(mx));
            book_num++;
        }
        st.insert(pp[i].second);
        sum+=pp[i].second;
        book_num=pp[i].first;
    }
    while(st.size()){
        int mx=*st.rbegin();
        ans+=sum-mx;
        sum-=mx;
        st.erase(st.find(mx));
    }
    cout<<ans<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值