2015 Multi-University Training Contest 6 Solutions

先放上官方答案,完整版请戳: http://bestcoder.hdu.edu.cn/blog/

-------------------------大家好我是分割线----------------------

1011.Key Set

Summary

For a given set {1, 2, . . . , nn}, you are to find the number of nonempty subsets with even sum.

Solution

Let aa be the number of even integers and bb be the number of even integers. The answer is:

2^{a}(\begin{pmatrix}b\0 \end{pmatrix}+\begin{pmatrix}b\2 \end{pmatrix}+2a((b0)+(b2)+)=2^{a+b-1}=2^{n-1}-1)=2a+b1=2n11

Time complexity: O(log\ n)O(log n)

----------------------大家好我是分割线------------------------


    作为一支酱油队,我们不负众望的只做出了水题(1011)。下面附上代码:

#include <stdio.h>
#include <iostream>
#define NUM 1000000007
using namespace std;

long long d[10000000];

long long def(int n)
{
    if(n<10000000)
    {
        return d[n];
    }
    return (def(n/2)*def(n-n/2))%NUM;
}

int main()
{
    long long n;
    int t;

    d[0]=1;
    for(int i=1;i<10000000;i++)
    {
        d[i]=(d[i-1]*2)%NUM;
    }

    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld",&n);
        long long ans = def(n-1)-1;
        printf("%lld\n",ans);
    }
    return 0;
}

    我们做着做着,突然发现如何快速得到2的n次方似乎是个问题,又不能开出10^9大小的数组,所以干脆开了个10^8大小的数组保存2^i,当所给的n大于10^8时,二分即可。递归树只有5层,速度还是很快的。

转载于:https://my.oschina.net/bgbfbsdchenzheng/blog/488815

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值