https://codeforces.com/contest/1737
A. Ela Sorting Books

题目大意:

给定长度为n的字符串,我们要把它分成k个部分,求每个部分的MEX,以此达到字符串字典序最大。

input 
5
12 3
cabccadabaac
12 6
cabccadabaac
12 12
cabccadabaac
25 1
abcdefghijklmnopqrstuvwxy
10 5
bcdxedbcfg

output 
edb
ccbbba
bbbbbaaaaaaa
z
aaaaa
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=200200,M=2002;
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n,k;
        cin>>n>>k;
        string s;
        cin>>s;
        map<char,int> mp;
        for(int i=0;i<s.size();i++)
        {
            if((s[i]-'a')<(n/k)) mp[s[i]-'a']++;
        }
        vector<int> v;
        int t=k;
        while(t--)
        {
            for(int i=0;i<=n/k;i++)
            {
                if(mp[i]==0)
                {
                    v.push_back(i);
                    break;
                }
                else mp[i]--;
            }
        }
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        for(int i=0;i<v.size();i++)
            cout<<(char)(v[i]+97);
        cout<<endl;
    }
    return 0;
}

B. Ela’s Fitness and the Luxury Number

题目大意:

给定一个区间l,r

问我们里面满足条件的数字有多少个?

条件就是一个整数x可以整除根号x。
input 
5
8 19
8 20
119 121
1 100000000000000000
1234567891011 1000000000000000000
output 
5
6
2
948683296
2996666667

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15…….
1 1 1 2 —2—2 3 — — 3 — — — 3……

  • 我们通过手动模拟可以跟清楚的看到每个数字能够被整除的数字就只有3个,分别是x * x,x * (x+1), x * (x+2);
  • 所以我们只需要模拟一下就行了
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=200200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL l,r;
        cin>>l>>r;
        LL x=sqrtl(l),y=sqrtl(r);
        LL ans=0;
        if(x!=y)//不同的数字下
        {
            //先处理左边界
            if(x*x==l) ans+=3;
            else if(l<=x*(x+1)) ans+=2;
            else if(l<=x*(x+2)) ans++;

            //再处理右边界
            if(y*(y+2)==r) ans+=3;
            else if(y*(y+1)<=r) ans+=2;
            else if(y*y<=r) ans++;
            
            //中间部分就直接*3
            cout<<ans+(y-x-1)*3<<endl;
        }
        else//同一个数字下,就看这三个对不对得上
        {
            if(l<=(x*x)&&(x*x)<=r) ans++;
            if(l<=(x*(x+1))&&(x*(x+1)<=r)) ans++;
            if(l<=(x*(x+2))&&(x*(x+2)<=r)) ans++;
            cout<<ans<<endl;
        }
    }
    return 0;
}

C. Ela and Crickets

题目大意:

给定一个边界n,在这个棋盘上有三个点,这三个点可以组成一个L(四个方位,可以翻转)

每次只需要有一个点在我想去的点的中间的时候,我就可以跨过这个点然后跳过去。

再给出一个目标点,问我们可不可以跳过去??

input 
6
8
7 2 8 2 7 1
5 1
8
2 2 1 2 2 1
5 5
8
2 2 1 2 2 1
6 6
8
1 1 1 2 2 1
5 5
8
2 2 1 2 2 1
8 8
8
8 8 8 7 7 8
4 8
output 
YES
NO
YES
NO
YES
YES

这个题目我们也可以手动模拟一下,就可以发现它可以跳九宫格的外面八个格子,但是中间那个是无论怎样都跳不到的
还有一个特别重要的就是:
如果实在边界上,那么斜跳不成立,所以我们就只能横着或者是竖着,这个情况需要提出来特判【卡了好久,我是呆比】

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL N=500200,M=2002;
LL x[N],y[N];
LL a[M][M];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        LL xx,yy;
        map<LL,LL> mpx,mpy;
        for(LL i=1;i<=3;i++)
        {
            cin>>x[i]>>y[i];
            mpx[x[i]]++;
            mpy[y[i]]++;
            if(mpx[x[i]]==2) xx=x[i];
            if(mpy[y[i]]==2) yy=y[i];
        }
        xx--;
        yy--;
        LL r,c;
        cin>>r>>c;
        //如果L的拐点恰好在棋盘的一角,不能斜向走
        //只能从拐点走到所在的那一行或那一列
        if((xx==0||xx==n-1)&&(yy==0||yy==n-1))
        {
            if(xx+1==r||yy+1==c) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        else if(abs(r-xx)%2==0&&abs(c-yy)%2==0) cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
        mpx.clear();
        mpy.clear();
    }
    return 0;
}

原文地址:http://www.cnblogs.com/Vivian-0918/p/16806824.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性