原题链接: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. ubuntu 16.04下如何打造 sublime python编程环境

    一.安装python3     ubuntu自身是安装python2的,例如在ubuntu 16.04中安装的就是python2.7.但我想在python3的环境下进行开发所以就要安装python3. ...

  2. UVA - 11134 Fabled Rooks问题分解,贪心

    题目:点击打开题目链接 思路:为了满足所有的车不能相互攻击,就要保证所有的车不同行不同列,于是可以发现,行与列是无关的,因此题目可以拆解为两个一维问题,即在区间[1-n]之间选择n个不同的整数,使得第 ...

  3. MIP启发式算法:Variable fixing heuristic

    *本文主要记录及分享学习到的知识,算不上原创 *参考文章见链接. 本文简单介绍一下Variable fixing heuristic,这个算法同样以local search为核心框架,它的特点在于定义 ...

  4. js 常用判断

    JS三元运算符 三元运算符: 如名字表示的三元运算符需要三个操作数. 语法是 条件 ? 结果1 : 结果2;. 这里你把条件写在问号(?)的前面后面跟着用冒号(:)分隔的结果1和结果2.满足条件时结果 ...

  5. [转] babel-present-env 与 babel-polyfill 学习总结

    babelrc 配置文件 { "presets": [ [ "env", { "modules": false, "useBuil ...

  6. luogu2698 [USACO12MAR]花盆Flowerpot

    单调队列+二分答案 #include <algorithm> #include <iostream> #include <cstring> #include < ...

  7. Andorid 生成NDK动态链接库 .so库

    .so库第一次见到是在搜索Android保存静态秘钥等特殊id字段做法时看到的-通过NDK的方式将静态秘钥保存在so文件中, 关于原生开发工具包(NDK)详细见官网指南要更详细,这里我记录我度娘各种结 ...

  8. [git 学习篇] 关联github和本地创库

    所以,github和本地创库是通过ssh传送,所以要将公钥拷贝到远程创库上(比如我ssh 远程服务器时,先将本地的公钥,拷贝到远程服务器的某个文件上(http://www.cnblogs.com/li ...

  9. Android中当前墙纸Wallpaper存放的位置

    最近想做个应用保存当前墙纸,找了一下,发现当前墙纸的位置在. /System/users/0/wallpaper 没有后缀.导出来修改一下名字就可以看到图标了.比如改为png. 但是,这个目录要求系统 ...

  10. 自定义AlertView(Swift)

    MyAlertView.swift // Pop Up Styles enum MyAlertViewStyle: Int { case success case error case notice ...