1662: [Usaco2006 Nov]Round Numbers 圆环数 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 337 Solved:
1662: [Usaco2006 Nov]Round Numbers 圆环数
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 337 Solved: 194
[Submit][Status][Discuss]
Description
正如你所知,奶牛们没有手指以至于不能玩“石头剪刀布”来任意地决定例如谁先挤奶的顺序。她们甚至也不能通过仍硬币的方式。 所以她们通过"round number"竞赛的方式。第一头牛选取一个整数,小于20亿。第二头牛也这样选取一个整数。如果这两个数都是 "round numbers",那么第一头牛获胜,否则第二头牛获胜。 如果一个正整数N的二进制表示中,0的个数大于或等于1的个数,那么N就被称为 "round number" 。例如,整数9,二进制表示是1001,1001 有两个'0'和两个'1'; 因此,9是一个round number。26 的二进制表示是 11010 ; 由于它有2个'0'和 3个'1',所以它不是round number。 很明显,奶牛们会花费很大精力去转换进制,从而确定谁是胜者。 Bessie 想要作弊,而且认为只要她能够知道在一个指定区间范围内的"round numbers"个数。 帮助她写一个程序,能够告诉她在一个闭区间中有多少Hround numbers。区间是 [start, finish],包含这两个数。 (1 <= Start < Finish <= 2,000,000,000)
Input
* Line 1: 两个用空格分开的整数,分别表示Start 和 Finish。
Output
* Line 1: Start..Finish范围内round numbers的个数
Sample Input
Sample Output
输出解释:
2 10 1x0 + 1x1 ROUND
3 11 0x0 + 2x1 NOT round
4 100 2x0 + 1x1 ROUND
5 101 1x0 + 2x1 NOT round
6 110 1x0 + 2x1 NOT round
7 111 0x0 + 3x1 NOT round
8 1000 3x0 + 1x1 ROUND
9 1001 2x0 + 2x1 ROUND
10 1010 2x0 + 2x1 ROUND
11 1011 1x0 + 3x1 NOT round
12 1100 2x0 + 2x1 ROUND
HINT
Source
Silver
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
using namespace std;
int f[51][51];
int st,ed,ans;
int n,m,t[51];
void init()
{for(int i=0;i<=50;i++)f[i][0]=1;for(int i=1;i<=50;i++)for(int j=1;j<=i;j++)f[i][j]=f[i-1][j]+f[i-1][j-1];
}
int cal(int x,int y)
{int ret=0;for(int i=0;i<=x;i++)if(i>=x-i+y)ret+=f[x][i];return ret;
}
int get(int x)
{if(!x)return 0;int len=0;while(x){t[++len]=x&1;x>>=1;}int tmp=0;for(int i=1;i<len;i++)tmp+=cal(i-1,1);int duo=1;len--;while(len){if(t[len]==1)tmp+=cal(len-1,duo-1);duo+=t[len]?1:-1;len--;}tmp+=duo<=0;return tmp;
}int main()
{init();scanf("%d%d",&st,&ed); printf("%d\n",get(ed)-get(st-1));
}
1662: [Usaco2006 Nov]Round Numbers 圆环数 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 337 Solved:相关推荐
- BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数(数位DP+恶心细节)
BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 Time Limit: 5 Sec Memory Limit: 64 MB Description 正如你所知 ...
- bzoj 1662: [Usaco2006 Nov]Round Numbers 圆环数(枚举)
1662: [Usaco2006 Nov]Round Numbers 圆环数 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 413 Solved: 2 ...
- 牛客假日团队赛5 F 随机数 BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 (dfs记忆化搜索的数位DP)...
链接:https://ac.nowcoder.com/acm/contest/984/F 来源:牛客网 随机数 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言6 ...
- [BZOJ1724][Usaco2006 Nov]Fence Repair 切割木板
1724: [Usaco2006 Nov]Fence Repair 切割木板 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1272 Solved: ...
- 1724: [Usaco2006 Nov]Fence Repair 切割木板( 贪心 )
倒过来看 , 每次总是选择最短的两块木板合并 , 用heap维护 ------------------------------------------------------------------- ...
- [BZOJ1726][Usaco2006 Nov]Roadblocks第二短路
1726: [Usaco2006 Nov]Roadblocks第二短路 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1277 Solved: 607 ...
- BZOJ 1724: [Usaco2006 Nov]Fence Repair 切割木板
题目 1724: [Usaco2006 Nov]Fence Repair 切割木板 Time Limit: 5 Sec Memory Limit: 64 MB Description Farmer ...
- bzoj 1726: [Usaco2006 Nov]Roadblocks第二短路(A*第k短路)
1726: [Usaco2006 Nov]Roadblocks第二短路 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 1324 Solved: 627 ...
- bzoj 1661: [Usaco2006 Nov]Big Square 巨大正方形(枚举)
1661: [Usaco2006 Nov]Big Square 巨大正方形 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 467 Solved: 23 ...
最新文章
- 运算方法和运算部件二
- C++实现线段树(lazy-tag方法)-区间修改,区间查询
- EasyDSS高性能流媒体服务器前端重构(五)- webpack + vue-router 开发单页面前端实现按需加载 - 副本...
- android gradle错误,Android studio gradle错误与顶级异常
- dump的文件 查看pg_PostgreSQL 逻辑复制异常引发Pg_wal目录WAL文件膨胀一例
- 3月7日 当前动力电池竞争格局
- word计算机课实验报告,Word 文字处理实验报告
- ThinkPad E450 10.11 驱动HD4400的注意即解决方法
- 婚姻是一场精神上的门当户对
- jstl 无法自动加载c.tld文件
- BeanUtilsVo.copyProperties源码分析
- CAPICAPICOM的一些知识[转]
- 系统重构的原则代码重构的原则
- Web前端:中国环宇科技有限公司网页设计
- 创建一个动态空间存储未知大小的二维数组
- 万年历农历法定节假日数据查询工具
- servlet容器,web容器,spring容器,springmvc容器的区别
- shell脚本(linux)
- FC协议功能子模块,实现FC-1553协议,ASM协议,AV协议的应用,多种接口可定制
- 命令Javascript控制台