【Malek Dance Club】【CodeForces - 320C】(數學+思維)
題目:
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 2nmembers and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n
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
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
解題報告:給序列0,1,2,……2^n-1 都異或上x ,問逆序對數。上來啥思路沒有,只好暴力打表找規律。得出規律將輸入的二進位制數轉化為十進位制,然後這個數字再乘上2^(長度-1),最後得到的就是正解。
ac程式碼:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn =1e6+100;
char str[maxn];
int main()
{
while(scanf("%s",str)!=EOF)
{
int n=strlen(str);
ll num=0;
ll sum=0;
for(int i=n-1;i>=0;i--)
{
if(str[i]=='1')
{
ll tmp=1;
for(int i=0;i<num;i++)
{
tmp=tmp*2;
tmp%=1000000007;
}
sum+=tmp;
}
num++;
}
for(ll i=0;i<n-1;i++)
{
sum=sum*2;
sum%=1000000007;
}
printf("%lld\n",sum);
}
}