BestCoder Round #44

1001:简单的模拟题

#include <iostream>
#include <cstdio>
using namespace std;
int d[4]= {400,600,800,1000};
int s[4]= {1000,1500,2000,2500};
int main()
{
    int T;
    scanf("%d",&T);
    for(int t=1; t<=T; ++t)
    {
        int sum=0;
        int a,b;
        for(int i=0; i<4; ++i)
        {
            scanf("%d%d",&a,&b);
            int tmp=s[i]/250*(250-a)-b*50;
            if(tmp<d[i])
                tmp=d[i];
            sum+=tmp;
        }
        printf("Case #%d: %d\n",t,sum);
    }
    return 0;
}
1002:字典树

解析:普通方法对于O(n^2),当n=50000时会超时

分析题目意思可以设法将数字按位归类,统计每个数字最早出现1的位置,然后将最早出现1的位置的数与在这之前

未出现1的数进行运算,但这样会出现一种问题:当两个数第一个出现1的位置相同时,我们需要寻找下一个不同

的1的位置。此时联想到字典树。此题到此结束

#include <cstdio>
using namespace std;
typedef long long LL;
const int MAX=50010;
const LL MOD=998244353;
int F[31];
struct Trie
{
    int sum;
    Trie* nxt[2];
    Tire()
    {
        sum=0;
        nxt[0]=nxt[1]=NULL;
    }
};

void Trie_add(Trie* root,int x)
{
    for(int i=0; i<=30; i++)
    {
        int w=((x&(1<<i))!=0);
        if(root->nxt[w]==NULL)
            root->nxt[w]=new Trie();
        root=root->nxt[w];
        root->sum++;
    }
}
void init()
{
    for(int i=0; i<=30; ++i)
        F[i]=1<<i;
}
LL solve(Trie* root,int cnt)
{
    LL ret=0,l,r;
    if(root->nxt[0]==NULL) l=0;
    else
    {
        l=root->nxt[0]->sum;
        ret=(ret+solve(root->nxt[0],cnt+1))%MOD;
    }
    if(root->nxt[1]==NULL) r=0;
    else
    {
        r=root->nxt[1]->sum;
        ret=(ret+solve(root->nxt[1],cnt+1))%MOD;
    }
    ret+=l*r*F[cnt]%MOD;
    return ret;
}


int main()
{
    int T;
    scanf("%d",&T);
    init();
    for(int t=1; t<=T; ++t)
    {
        int n;
        scanf("%d",&n);
        Trie* root=new Trie();///字典树根节点为空
        int tmp;
        for(int i=1; i<=n; ++i)
        {
            scanf("%d",&tmp);
            Trie_add(root,tmp);
        }
        printf("Case #%d: %I64d\n",t,solve(root,0)*2%MOD);
    }
    return 0;
}
1003:

1004:


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值