HDU 4349 Xiao Ming's Hope 找规律

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4349

Xiao Ming‘s Hope

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1723    Accepted Submission(s): 1144

Problem Description

Xiao Ming likes counting numbers very much, especially he is fond of counting odd numbers. Maybe he thinks it is the best way to show he is alone without a girl friend. The day 2011.11.11 comes. Seeing classmates walking with their girl friends, he coundn‘t help running into his classroom, and then opened his maths book preparing to count odd numbers. He looked at his book, then he found a question "C(n,0)+C(n,1)+C(n,2)+...+C(n,n)=?". Of course, Xiao Ming knew the answer, but he didn‘t care about that , What he wanted to know was that how many odd numbers there were? Then he began to count odd numbers. When n is equal to 1, C(1,0)=C(1,1)=1, there are 2 odd numbers. When n is equal to 2, C(2,0)=C(2,2)=1, there are 2 odd numbers...... Suddenly, he found a girl was watching him counting odd numbers. In order to show his gifts on maths, he wrote several big numbers what n would be equal to, but he found it was impossible to finished his tasks, then he sent a piece of information to you, and wanted you a excellent programmer to help him, he really didn‘t want to let her down. Can you help him?

Input

Each line contains a integer n(1<=n<=108)

Output

A single line with the number of odd numbers of C(n,0),C(n,1),C(n,2)...C(n,n).

Sample Input

1
2
11

Sample Output

2
2
8

Author

HIT

Source

2012 Multi-University Training Contest 5

Recommend

zhuyuanchen520

题意

给你个n,问你第n行的二项式系数中有多少个奇数项。

题解

就打打表找规律,发现答案就是n的二进制中1的个数的二的幂。

代码

#include<cstdio>
#include<bitset>
int n;
int main(){
    while(scanf("%d",&n)==1){
        std::bitset<63> bi(n);
        printf("%d\n",1<<(bi.count()));
    }
    return 0;
}

HDU 4349 Xiao Ming's Hope 找规律

时间: 2024-08-04 18:30:33

HDU 4349 Xiao Ming's Hope 找规律的相关文章

hdu 4349 Xiao Ming&#39;s Hope 规律

Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Xiao Ming likes counting numbers very much, especially he is fond of counting odd numbers. Maybe he thinks it is the best way to

HDU 4349 Xiao Ming&#39;s Hope

很无语的一个题. 反正我后来看题解完全不是一个道上的. 要用什么组合数学的lucas定理. 表示自己就推了前面几个数然后找找规律. C(n, m) 就是 组合n取m: (m!(n-m!)/n!) 如果n==11 : C(11,0):C(11,1):C(11,2):C(11,3):C(11,4):C(11,5): 分别为 (1/1); (1 / 11) ; (11*10 / 2*1)  ;   (11*10*9 / 3*2*1); (11*10*9*8 / 4*3*2*1) ;  (11*10*9

HDU 4349 Xiao Ming&#39;s Hope 组合数学

题意:给你n,问在C(n,1),C(n,2)...C(n,n)中有多少个奇数. 比赛的时候打表看出规律,这里给一个数学上的说明. Lucas定理:A,B非负整数,p是质数,A,B化为p进制分别为a[n]a[n-1]...a[0],b[n]b[n-1]...b[0]. 那么组合数C(A,B)与C(a[n],b[n])*...*C(a[0],b[0])模p同余. 证明就不说了,我也不会,给个链接  Lucas定理证明 那再来看这道题就简单了,p=2,C(0,1)=0,C(1,0) = C(1,1)

HDU 4349 Xiao Ming&#39;s Hope &amp; HDU 6129 Just do it

组合数学中有这这样一个神奇的定理:如果对于两个数n.m,如果(n&m)==m,那么C(n,m)为奇数,否则为偶数. 这个其实很容易证明的把C(n,m)化为阶乘表示:n!/(n!*(n-m)!),如果C(n,m)为奇数除式上方和下方所含有的2的个数应该是一样的,不一样的话肯定为偶数.而n!含2的阶乘的数量其实就是看这个数一直除2然后每次结果加一下知道了,但这样所有数都计算的话复杂度其实还是很大的.那么还有其他的更优算法吗?其实一个数x的阶乘含有质因数2的个数等于x-__builtin_popcou

HDU 4349 Xiao Ming&#39;s Hope (Lucas)

题意:给定一个 n,问你在 C(n, 0) - C(n , n) 中有多少个奇数. 析:Lucas定理,C(b[i], a[i]),只要不为0,那么就是奇数,然后b[i],是固定的,也就是说a[i] 只有 b[i]+1种情况.最后乘起来就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <

HDU 4349 Xiao Ming&#39;s Hope(数学题,Lucas定理)

解题思路: 深入理解lucas定理. Lucas定理:把n写成p进制a[n]a[n-1]a[n-2]...a[0],把m写成p进制b[n]b[n-1]b[n-2]...b[0],则C(n,m)与C(a[n],b[n])*C(a[n-1],b[n-1])*C(a[n-2],b[-2])*....*C(a[0],b[0])模p同余. 这题p为2,所以a[i]和b[i]为0或者1.又因为C(1,0), C(1,1), 即当n等于1时,结果才等于1. 所以写出n的二进制,m从0遍历到n,每一次遍历把m写

HDU 4349 Xiao Ming&#39;s Hope lucas定理

Xiao Ming's Hope Time Limit:1000MS     Memory Limit:32768KB Description Xiao Ming likes counting numbers very much, especially he is fond of counting odd numbers. Maybe he thinks it is the best way to show he is alone without a girl friend. The day 2

hdu 4349 Xiao Ming&#39;s Hope (Lucas定理推导)

题意:求C (n,0),C (n,1),C (n,2)...C (n,n).奇数的个数 思路:我们分析C(n,m)%2,那么由Lucas定理可知,n和m可以写成二进制的形式,假设n=1001101,那么m是0~1001101,我们知道C(0,1)=0,因此如果n=1001101的0对应位置的m二进制位为1那么C(n,m) % 2==0,因此m对应n为0的位置只能填0,而1的位置填0,填1都是1(C(1,0)=C(1,1)=1),不影响结果为奇数,并且保证不会出n的范围,因此所有的情况即是n中1位

HDU 4349——Xiao Ming&#39;s Hope——————【Lucas定理】

Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1786    Accepted Submission(s): 1182 Problem Description Xiao Ming likes counting numbers very much, especially he is fond of cou