原题链接: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. Python简单试题2

    1,给定一组数据,将奇数进行从小到大排序,偶数在原位置不变 例: 原数据:[5, 3, 2, 8, 1, 4]   排序后:[5, 3, 2, 8, 1, 4] 若数组为空,则返回空数组. 代码如下: ...

  2. Python9-网络编程2-day31

    基于UDP协议的socket #server import socket sk = socket.socket(type=socket.SOCK_DGRAM) sk.bind(('127.0.0.1' ...

  3. LeetCode(217)Contains Duplicate

    题目 Given an array of integers, find if the array contains any duplicates. Your function should retur ...

  4. Hadoop4.2HDFS测试报告之四

    第二组:文件存储读过程记录 测试系统组成 存储类型 测试程序或命令 测试文件大小(Mb) 文件个数(个) 客户端并发数(个) 读速率 (M/s) NameNode:1 DataNode:1 本地存储 ...

  5. 【Jenskins】安装与配置

    Jenskins教程:http://www.yiibai.com/jenkins/ 一.Jenskins的安装 1.jenskins下载和启动 Jenskins下载地址:https://jenkins ...

  6. socket编程了解

    Socket 编程 Socket通讯原理描述: 套接字是为特定网络协议(例如TCP/IP,ICMP/IP,UDP/IP等)套件对上的网络应用程序提供者提供当前可移植标准的对象.它们允许程序接受并进行连 ...

  7. Python_Virtualenv及Pycharm配置

    Virtualenv存在的意义 在Python使用过程中,你是否有遇到过同时需要开发多个应用的情况? 假设A应用需要使用DJango1.X版本,而B应用需要使用DJango2.X的版本,而你全局开发环 ...

  8. MySQL 8.* 账号密码管理

    修改密码: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的新密码' 通过以下命令可以查看修改的账号 ...

  9. 【转载】用OCTAVE实现一元线性回归的梯度下降算法

    原文地址:http://www.cnblogs.com/KID-XiaoYuan/p/7247481.html STEP1 PLOTTING THE DATA 在处理数据之前,我们通常要了解数据,对于 ...

  10. 阿里云 fatal: Authentication failed 退出码 128

    阿里云拉取代码时需要输入的用户名密码 跟我们登录aliyun的时候的账号密码不一样,需要先重置一下的,重置之前要配置好邮箱 https://code.aliyun.com/profile/passwo ...