栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

Codeforces Round #757 (Div. 2)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Codeforces Round #757 (Div. 2)

Codeforces Round #757 (Div. 2) A. Divan and a Store 分析:
  • 贪心
#include 
#define int long long 
using namespace std;

const int N=1e6+5;
int a[N];
void solve()
{
    int n,l,r,k;
    cin>>n>>l>>r>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+1+n);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]>=l && a[i]<=r && a[i]<=k) 
        {
            ans++;
            k-=a[i];
        }
    }
    cout<>T;
    while(T--) solve();
}
B. Divan and a New Project 分析:
  • 贪心+排序
#include 
#define int long long 
using namespace std;

const int N=1e6+5;
struct node
{
    int a,id;
    bool operator < (const node &b) { return a>b.a; }
}e[N];

int ans[N];
void solve()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) 
    {
        ans[i]=0;
        cin>>e[i].a;
        e[i].id=i;
    }
    sort(e+1,e+1+n);
    int tot=0,sum=0;
    for(int i=1;i+1<=n;i+=2)
    {
        ans[e[i].id]=++tot;
        ans[e[i+1].id]=-tot;
        sum+=2*(tot)*(e[i].a+e[i+1].a);
    }
    if(n&1) 
    {
        ans[e[n].id]=++tot;
        sum+=2*(tot)*(e[n].a);
    }
    cout<>T;
    while(T--) solve();
}
C. Divan and bitwise operations 分析:
  • 组合数学+亦或的一个性质

  • 最后要输出的是所有 子序列亦或和 的和

  • 现单独考虑最低位的贡献情况

    子序列的个数为 2 n 2^n 2n 个,假设 n n n 个数中有 k k k 个数的最低位为 1

    那么最低为的贡献情况为:
    2 0 ( C k 1 + C k 3 + C k 5 + . . . ) ∗ 2 n − k = 1 ∗ 2 k − 1 ∗ 2 n − k = 2 n − 1 2^{0}(C_{k}^1+C_{k}^3+C_{k}^5+...)*2^{n-k}=1*2^{k-1}*2^{n-k}=2^{n-1} 20(Ck1​+Ck3​+Ck5​+...)∗2n−k=1∗2k−1∗2n−k=2n−1

  • 故只要某一位有 1 ,就会有贡献

  • a n s = ( x 1 ∣ x 2 ∣ . . . ∣ x m ) ∗ 2 n − 1 ans=(x_1|x_2|...|x_m)*2^{n-1} ans=(x1​∣x2​∣...∣xm​)∗2n−1

#include 
#define int long long 
using namespace std;

const int mo=1e9+7;
int ksm(int a,int b,int p=mo)
{
    int ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%p;
        a=a*a%p; b>>=1;
    }
    return ans;
}
void solve()
{
    int n,m;
    cin>>n>>m;
    int ans=0;
    for(int i=1;i<=m;i++)
    {
        int l,r,x;
        cin>>l>>r>>x;
        ans|=x;
    }
    ans%=mo;
    ans=ans*ksm(2,n-1)%mo;
    cout<>T;
    while(T--) solve();
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/604188.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号