原题链接: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
 
Recommend
zhuyuanchen520

题意

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

题解

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

代码

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

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

  1. hdu 4349 Xiao Ming's Hope 规律

    Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 4349 Xiao Ming's Hope lucas定理

    Xiao Ming's Hope Time Limit:1000MS     Memory Limit:32768KB  Description Xiao Ming likes counting nu ...

  3. HDU 4349——Xiao Ming's Hope——————【Lucas定理】

    Xiao Ming's Hope Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. HDU 4349 Xiao Ming&#39;s Hope

    非常无语的一个题. 反正我后来看题解全然不是一个道上的. 要用什么组合数学的lucas定理. 表示自己就推了前面几个数然后找找规律. C(n, m) 就是 组合n取m: (m!(n-m!)/n!) 假 ...

  5. HDU 4349 Xiao Ming's Hope 组合数学

    题意:给你n,问在C(n,1),C(n,2)...C(n,n)中有多少个奇数. 比赛的时候打表看出规律,这里给一个数学上的说明. Lucas定理:A,B非负整数,p是质数,A,B化为p进制分别为a[n ...

  6. HDU 4349 Xiao Ming's Hope

    有这样一个性质:C(n,m)%p=C(p1,q1)*C(p2,q2).......%p,其中pkpk-1...p1,qkqk-1...q1分别是n,m在p进制下的组成. 就完了. #include&l ...

  7. hdu 4349 Xiao Ming's Hope lucas

    题目链接 给一个n, 求C(n, 0), C(n, 1), ..........C(n, n)里面有多少个是奇数. 我们考虑lucas定理, C(n, m) %2= C(n%2, m%2)*C(n/2 ...

  8. HDU 4349 Xiao Ming's Hope [Lucas定理 二进制]

    这种题面真是够了......@小明 题意:the number of odd numbers of C(n,0),C(n,1),C(n,2)...C(n,n). 奇数...就是mod 2=1啊 用Lu ...

  9. hdu 2865 Polya计数+(矩阵 or 找规律 求C)

    Birthday Toy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

随机推荐

  1. oracle如何保证读一致性 第一弹

    oracle保证读一致性原理   1:undo segment的概念                   当数据库进行修改的时候,需要把保存到以前的old的数据保存到一个地方,然后进行修改,用于保存o ...

  2. Linux操作系统启动流程

    一般来说,所有的操作系统的启动流程基本就是: 总的来说,linux系统启动流程可以简单总结为以下几步:1)开机BIOS自检,加载硬盘.2)读取MBR,进行MBR引导.3)grub引导菜单(Boot L ...

  3. debian安装中文字体

    debian刚安装完成之后,因为没有中文字体,会出现方框. 安装中文字体: $ su # apt-get install fonts-arphic-bkai00mp fonts-arphic-bsmi ...

  4. SQL_4_函数

    在SQL的函数中可以执行一些诸如对某一些进行汇总或将一个字符串中的字符转换为大写的操作等: 函数有:汇总函数.日期与时间函数.数学函数.字符函数.转换函数与其他函数. 汇总函数 这是一组函数,它们返回 ...

  5. gdb调试手册 一 gdb概述

    一 gdb概述 gdb调试器的目的是让你了解其他的程序在执行的时候发生了什么或者其他程序崩溃时正在做什么 gdb主要能够在运行中做四类事情(包括这些事情中的一些附加的事情)来帮助你获取bugs a 运 ...

  6. GCC内嵌汇编一些限制字符串

    /******************/ “b”将输入变量放入ebx “c”将输入变量放入ecx “d”将输入变量放入edx “s”将输入变量放入esi “d”将输入变量放入edi “q”将输入变量放 ...

  7. Python循环语句 if while for

    流程控制: if 条件1: 缩进的代码块 (注意缩进4个空格) elif 条件2: 缩进的代码块 elif 条件3: 缩进的代码块 ...... else: 缩进的代码块 注意1:(相同的代码块儿,同 ...

  8. linux下文件显示被加锁如何解决?

    1.很多时候从别的机器上拷贝过来的文件,没有权限打开,上面有一个小锁. 2.判断是权限没有,查询ls -al得知文件的的所有者,和所有者在的组都不是本机 3.使用chown改变用户的所有者和所有者所在 ...

  9. 编译安装solr

    1, 获取安装包 wget http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.rpm wget htt ...

  10. 【Luogu】P1903数颜色(带修改莫队)

    题目链接 带修改莫队模板. 加一个变量记录现在是第几次修改,看看当前枚举的询问是第几次修改,改少了就改过去,改多了就改回来. 话说我栈用成队列了能过样例?!!!! 从此深信一句话:样例是出题人精心设计 ...