Codeforces 320C Malek Dance Club【规律】

175 篇文章 2 订阅

C. Malek Dance Club
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.

One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.

The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.

You are given a binary number of length n named x. We know that member i from MDC dances with member  from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).

Expression  denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor».

Input

The first line of input contains a binary number x of lenght n(1 ≤ n ≤ 100).

This number may contain leading zeros.

Output

Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).

Examples
input
11
output
6
input
01
output
2
input
1
output
1

题目大意:


给出一个长度为n的二进制数,现在有两队人,每个队都有2^n个人,第一队的第i个人,和第二队的第i^num(二进制数)个人进行跳舞,如果存在两对跳舞的人(a,b)和(c,d)其中保证a<c&&b>d的话,计数器加一,问一共有多少个这样的两对。


思路:


遇事不决先打表,打了表就观察到了规律。

Ans=二进制数转成十进制数之后*2^(n-1);


过程维护一下取模就行了。


Ac代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
#define ll __int64
char a[150000];
int main()
{
    while(~scanf("%s",a))
    {
        ll num=0;
        ll cont=0;
        ll n=strlen(a);
        for(ll i=n-1;i>=0;i--)
        {
            if(a[i]=='1')
            {
                ll tmp=1;
                for(ll j=0;j<cont;j++)
                {
                    tmp*=2;
                    tmp%=1000000007;
                }
                num+=tmp;
            }
            cont++;
        }
        for(ll i=0;i<n-1;i++)
        {
            num=num*2;
            num%=1000000007;
        }
        printf("%I64d\n",num);
    }
}







  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值