Codeforces Round #461 (Div. 2)

Posted walfy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #461 (Div. 2)相关的知识,希望对你有一定的参考价值。

A:sb题,多特判几下就好了

技术分享图片
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double g=10.0,eps=1e-9;
const int N=100000+10,maxn=3000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;


int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    if(y==1)
    {
        if(x!=0)puts("No");
        else puts("Yes");
        return 0;
    }
    if(x>=y-1&&(x-y+1)%2==0&&y!=0)puts("Yes");
    else puts("No");
    return 0;
}
/********************

********************/
A

B:n^2模拟

技术分享图片
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double g=10.0,eps=1e-9;
const int N=100000+10,maxn=3000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;


int main()
{
    int n,ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            int te=i^j;
            if(j<=te&&te<=n&&i+j>te&&i+te>j&&j+te>i)ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}
/********************

********************/
B

C:找从1到k中,有没有n%i相同的情况

直接暴力,因为打表出来的结果k不超过15

技术分享图片
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double g=10.0,eps=1e-9;
const int N=100000+10,maxn=3000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

map<ll,ll>vis;
int main()
{
    ll n,k;
    scanf("%lld%lld",&n,&k);
//    if(k>=n)puts("No");
//    else
    {
        bool ok=1;
        for(ll i=1;i<=k;i++)
        {
            if(vis[n%i])
            {
                ok=0;
                break;
            }
            else vis[n%i]=1;
        }
        if(ok)puts("Yes");
        else puts("No");
    }
    return 0;
}
/********************

********************/
C

D:给n个字符串,要求重拍后组成的字符串,价值最大,价值是满足i<j,s[i]==‘s‘&&s[j]==‘h‘的对数

做法:直接sort,判断条件是前后组合一下,看那种情况的价值最大,求价值直接后缀和h,扫一遍遇到s就加上后缀,复杂度O(nlogn)

技术分享图片
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double g=10.0,eps=1e-9;
const int N=100000+10,maxn=3000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

map<ll,ll>vis;
int main()
{
    ll n,k;
    scanf("%lld%lld",&n,&k);
//    if(k>=n)puts("No");
//    else
    {
        bool ok=1;
        for(ll i=1;i<=k;i++)
        {
            if(vis[n%i])
            {
                ok=0;
                break;
            }
            else vis[n%i]=1;
        }
        if(ok)puts("Yes");
        else puts("No");
    }
    return 0;
}
/********************

********************/
D

E:n颗数,每个树ci个鸟,从1开始依次移动,每次可以召唤1<=i<=ci只鸟,每召唤一只鸟需要costi法力值,每召唤一只鸟法力值上限加上b,每移到一颗树法力加x,要求找到最大能召唤的鸟个数

做法:dp[i][j]维护的是当访问到第i颗树时,召唤了j只鸟的当前最大法力值,初始状态dp[0][0]=w,转移方程dp[i][j]=max(dp[i][j],min(dp[i-1][j-k]+x,w+(j-k)*b)-cost[i]*k)

最后dp[n]里最大能访问到的地方就是答案

技术分享图片
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double g=10.0,eps=1e-9;
const int N=1000+10,maxn=3000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

ll dp[N][10000+10];
ll c[N],cost[N];
int main()
{
    ll n,w,b,x,sum=0;
    scanf("%lld%lld%lld%lld",&n,&w,&b,&x);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&c[i]);
        sum+=c[i];
    }
    for(int i=1;i<=n;i++)scanf("%lld",&cost[i]);
    memset(dp,-1,sizeof dp);
    dp[0][0]=w;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=sum;j++)
        {
            for(int k=0;k<=min((ll)j,c[i]);k++)
            {
                if(dp[i-1][j-k]==-1)continue;
//                if(min(dp[i-1][j-k]+x,w+b*(j-k))-cost[i]*k<0)continue;
                dp[i][j]=max(dp[i][j],min(dp[i-1][j-k]+x,w+b*(j-k))-cost[i]*k);
            }
        }
    }
    int ans=0;
    while(ans+1<=sum&&dp[n][ans+1]!=-1)ans++;
    printf("%d\n",ans);
    return 0;
}
/********************

********************/
E

F:给你n,k要求构造一个集合,满足集合里所有数不超过n,没有重复,满足倍数关系的对数有k对

做法:先求出1到n的满足倍数关系的对数e[i],如果e[n]<k,则1到n每个都有也不能满足条件输出no,否则yes,贪心的在1到n删数来满足条件,从1到n每次删除之后在对应的倍数因子数d[i]减一(至于这样贪心为什么能满足条件,我也不会证明,直觉上可以),复杂度O(nlogn)

技术分享图片
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double g=10.0,eps=1e-9;
const int N=300000+10,maxn=3000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

int d[N],e[N];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        for(int j=2*i;j<=n;j+=i)
            d[j]++;
    for(int i=1;i<=n;i++)e[i]=e[i-1]+d[i];
    if(e[n]<k)puts("No");
    else
    {
        vector<int>ans;
        int te=e[n]-k;
        for(int i=1;i<=n;i++)
        {
            if(te>=d[i]+n/i-1&&d[i]==1)
            {
                te-=d[i]+n/i-1;
                for(int j=2*i;j<=n;j+=i)d[j]--;
            }
            else ans.pb(i);
        }
        sort(ans.begin(),ans.end());
        puts("Yes");
        printf("%d\n",ans.size());
        for(int i=0;i<ans.size();i++)printf("%d ",ans[i]);
        puts("");
    }
    return 0;
}
/********************

********************/
F

 

以上是关于Codeforces Round #461 (Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #461 (Div. 2)

Codeforces-Round-#461-Div. 2-C

Codeforces Round #263 (Div.1) B. Appleman and Tree

Codeforces Round #436 E. Fire(背包dp+输出路径)

[ACM]Codeforces Round #534 (Div. 2)

Codeforces 461B Appleman and Tree