原题链接: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. tp5使用外部类的三种方法

    在tp5中使用外部类的时候有三种方法 第一种就是通过composer下载,通过这种方式下载的外部类能够支持自动加载,我们只要在使用的时候use一下命名空间就可以使用了 比如:我们的tp5第四季项目要使 ...

  2. Java-basic-7-面向对象

    继承 在Java中,每个子类只能有一个父类,但可以继承多个接口. 子类继承父类,类定义的时候用extends. 继承接口,用implements. 重写 声明为final的方法不能被重写. 声明为st ...

  3. Python并发编程之多进程(实战)

    一.multiprocessing和Process multiprocessing提供了支持子进程.通信和数据共享.执行不同形式的同步,提供了Process.Queue.Pipe.Lock等组件 创建 ...

  4. python基础学习笔记——类的约束

    ⾸先, 你要清楚. 约束是对类的约束. 用一个例子说话: 公司让小明给他们的网站完善一个支付功能,小明写了两个类,如下: class QQpay: def pay(self,money): print ...

  5. Python Cdn平台文件md5验证

    第一步 先用脚本实现基本的md5验证 1.python如何实现文件的下载 方法一: 使用 urllib 模块提供的 urlretrieve() 函数.urlretrieve() 方法直接将远程数据下载 ...

  6. Just a test

  7. 浅析win32 Win64 x86 x64 区别 及Eclipse启动报Java was started but returned exit code=13 错误

    win32.x86_64是64位 X86就是  32位系统 X64 就是64位系统 最好记得方法就是带有64的就是64位,其余都是32位 为什么要讲这个呢? 如果是绿色版本的eclipse,在打开ec ...

  8. jmeter进行dubbo接口测试

    最近工作中接到一个需求,需要对一个MQ消息队列进行性能测试,测试其消费能力,开发提供了一个dubbo服务来供我调用发送消息. 这篇博客,介绍下如何利用jmeter来测试dubbo接口,并进行性能测试. ...

  9. NuGet之控制台管理程序包

        NuGet作为VS的扩展程序,已经做好了UI,我们可以通过Manage NuGet Packages 的对话框.这里我们主要说说如何通过控制台进行包管理.使用命令行的方式,其实也是有其好处,对 ...

  10. RabbitMQ与PHP(一)

    RabbitMQ与PHP(一) 项目中使用RabbitMQ作为队列处理用户消息通知,消息由前端PHP代码产生,处理消息使用Python,这就导致代码一致性问题,调整消息定义时需要PHP和Python都 ...