(蒟蒻补题)Codeforces Round 966 (Div. 3) A-E





A - Primary Task

上来没审完题面wa了一发(),注意字符串小于等于2的情况

/*I lv ya*/
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N = 2e5+5;
string s;
void solve()
{
    cin>>s;
    if(s.size()<3||s[0]!='1'||s[1]!='0'||s[2]=='0'||stoll(s.substr(2))<2ll)
    {
        cout<<"NO"<<endl;
    }
    else
    {
        cout<<"YES"<<endl;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int _;
    cin>>_;
    while(_--)
    {
        solve();
    }
    return 0;
}

B - Seating in a Bus

用哈希记录一下点的两边即可

/*I lv ya*/
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N = 2e5+5;
int n,a[N];
map <int,bool> hs;
void solve()
{
    hs.clear();
    cin>>n;
    bool f=1;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i==1)
        {
            hs[a[i]]=1;
        }
        else
        {
            if(hs[a[i]-1]==0&&hs[a[i]+1]==0)
            {
                f=0;
            }
            hs[a[i]]=1;
        }
        //cout<<f<<endl;
    }
    if(f)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int _;
    cin>>_;
    while(_--)
    {
        solve();
    }
    return 0;
}

C - Numeric String Template

开两个map,一个记录字符对应的数字,一个记录数字对应的字符,前后有矛盾即可判断为否

/*I lv ya*/
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N = 2e5+5;
int n,m,a[N];
string s[N];
map <int,char> hsn;
map <char,int> hsc;
void solve()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    cin>>m;
    for(int i=1;i<=m;i++)
    {
        hsc.clear();
        hsn.clear();
        bool f=1;
        cin>>s[i];
        if(s[i].size()!=n)
        {
            f=0;
            cout<<"NO"<<endl;
            continue;
        }
        s[i]=" "+s[i];
        for(int j=1;j<=n;j++)
        {
            if(hsc[s[i][j]]==0&&hsn[a[j]]==0)
            {
                hsc[s[i][j]]=a[j];
                hsn[a[j]]=s[i][j];
            }
            else if(a[j]!=hsc[s[i][j]]||s[i][j]!=hsn[a[j]])
            {
                f=0;
            }
        }
        if(f)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int _;
    cin>>_;
    while(_--)
    {
        solve();
    }
    return 0;
}

D - Right Left Wrong

BYD交了好几发才过,忘记判断容器为空了

题目看着比较好理解。即使题目说的是外区间用完就不能用内区间了,但在这里我们依然先用外区间,因为发现并不冲突。

贪心可得让外区间包的越大越好,因此用一个小顶堆维护左区间,一个大顶堆维护右区间,然后用一次推出一次,直到 下一状态的左区间大于右区间 或者 有一个堆为空 时跳出循环,我们就得到了答案

原数组用前缀和维护

/*I lv ya*/
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N = 2e5+5;
ll n;
ll a[N],as[N];
string s;
void solve()
{
    memset(as,0,sizeof(as));
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        as[i]=as[i-1]+a[i];
    }
    cin>>s;
    s=" "+s;
    priority_queue<int,vector<int>,less<int> >rq;
    priority_queue<int,vector<int>,greater<int> >lq;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='L')
        {
            lq.push(i);
        }
        else
        {
            rq.push(i);
        }
    }
    ll ans=0;
    int r,l;
    if(rq.size()) r=rq.top();
    if(lq.size()) l=lq.top();
    while(l<r&&!rq.empty()&&!lq.empty())
    {
        lq.pop();
        rq.pop();
        ans+=as[r]-as[l-1];
        l=lq.top();
        r=rq.top();
    }
    cout<<max(ans,0ll)<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int _;
    cin>>_;
    while(_--)
    {
        solve();
    }
    return 0;
}

E - Photoshoot for Gorillas

题干非常的抽象,到最后才上的样例图解,非常离谱

有了这个图就基本明白了

我们需要做的就是尽可能让身高更高的猩猩被选中的次数更多

样例1:

每个格子被选中的次数如下:

1   2   2   1

2   4   4   2

1   2   2   1

所以让身高更高的猩猩占据中间选中次数为4的格子,我们就得到了4+4+2+2+2+2+2+2+1=21这个答案。

接下来要做什么?当然是记录每种被选中的情况出现的次数。使用二位前缀差分记录,再将二维前缀结果放入哈希表中,比如样例一中 4 出现了 2 次,2 出现了 6 次......因为m*n最多才2e5,空间和时间都是很充裕的。

这些工作做完之后只需要将 更高的猩猩匹配到被选中次数更多的格子 即可,排序、累加得到结果

/*I lv ya*/
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int N = 2e5+5;
ll n,m,k,w;
ll a[N];
map <ll,ll> hs;
vector <PII> vec;
bool cmp1(ll x,ll y)
{
    return x>y;
}
bool cmp(PII x,PII y)
{
    return x.first>y.first;
}
void solve()
{
    hs.clear();
    vec.clear();
    cin>>n>>m>>k>>w;
    ll mp[n+5][m+5];
    memset(mp,0,sizeof(mp));
    for(ll i=1;i<=w;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n-k+1;i++)
    {
        for(int j=1;j<=m-k+1;j++)
        {
            mp[i][j]++;
            mp[i+k][j]--;
            mp[i][j+k]--;
            mp[i+k][j+k]++;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            mp[i][j]=mp[i][j]-mp[i-1][j-1]+mp[i-1][j]+mp[i][j-1];
            hs[mp[i][j]]++;
        }
    }
    sort(a+1,a+w+1,cmp1);
    for(auto it:hs)
    {
        vec.push_back({it.first,it.second});
    }
    sort(vec.begin(),vec.end(),cmp);
    ll ans=0;
    int pos=0;
    ll now=vec[pos].second;
    for(int i=1;i<=w;i++)
    {
        ans+=a[i]*vec[pos].first;
        now--;
        if(now==0)
        {
            pos++;
            now=vec[pos].second;
        }
    }
    cout<<ans<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int _;
    cin>>_;
    while(_--)
    {
        solve();
    }
    return 0;
}

感谢观看,剩下的题目水平不够就不写了(

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值