bzoj1662: [Usaco2006 Nov]Round Numbers 圆环数
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
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
char ch;
bool ok;
void read(int &x){
ok=;
for (ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') ok=;
for (x=;isdigit(ch);x=x*+ch-'',ch=getchar());
if (ok) x=-x;
}
const int maxn=;
int l,r,c[maxn][maxn],cnt[maxn],a[maxn];
void init(){
for (int i=;i<=;i++) c[i][]=;
for (int i=;i<=;i++) for (int j=;j<=i;j++) c[i][j]=c[i-][j-]+c[i-][j];
cnt[]=;
for (int i=;i<=;i++) for (int j=i-,k=;j>=k;j--,k++) cnt[i]+=c[i-][j];
for (int i=;i<=;i++) cnt[i]+=cnt[i-];
}
int calc(int n){
int t=n,len=,ans=,tmp0=,tmp1=;
memset(a,,sizeof(a));
while (t) a[++len]=t&,t>>=;
for (int i=len;i;i--){
if (i==len) ans+=cnt[i-];
else if (a[i]){for (int j=i-;j+tmp0+>=tmp1+i--j;j--) ans+=c[i-][j];}
if (a[i]) tmp1++; else tmp0++;
}
return ans;
}
int main(){
init();
read(l),read(r);
printf("%d\n",calc(r+)-calc(l));
return ;
}
bzoj1662: [Usaco2006 Nov]Round Numbers 圆环数的更多相关文章
- 【分块打表】bzoj1662 [Usaco2006 Nov]Round Numbers 圆环数
#include<cstdio> using namespace std; #define BN 380000 const int table[]={0,185815,378154,561 ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- BZOJ_1662_[Usaco2006 Nov]Round Numbers 圆环数_数位DP
BZOJ_1662_[Usaco2006 Nov]Round Numbers 圆环数_数位DP Description 正如你所知,奶牛们没有手指以至于不能玩“石头剪刀布”来任意地决定例如谁先挤奶的顺 ...
- 【BZOJ】1662: [Usaco2006 Nov]Round Numbers 圆环数(数位dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1662 这道题折腾了我两天啊-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 果然 ...
- 牛客假日团队赛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 ...
- BZOJ1662: [Usaco2006 Nov]Round Numbers
1662: [Usaco2006 Nov]Round Numbers Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 147 Solved: 84[Sub ...
- [ACM] POJ 3252 Round Numbers (的范围内的二元0数大于或等于1数的数目,组合)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8590 Accepted: 3003 Des ...
- 4-圆数Round Numbers(数位dp)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14947 Accepted: 6023 De ...
- [BZOJ1662][POJ3252]Round Numbers
[POJ3252]Round Numbers 试题描述 The cows, as you know, have no fingers or thumbs and thus are unable to ...
随机推荐
- Debug调试
1.F5单步调试进入函数内部 2.F6单步调试进行下一步 3.F7由函数内部返回到调用用处 4.F8一直执行到下一个断点
- 【题解】A-B
[问题描述]出题是一件痛苦的事情!题目看多了也有审美疲劳,于是我舍弃了大家所熟悉的 A+B Problem,改用 A-B 了哈哈!好吧,题目是这样的:给出一串数以及一个数字 C,要求计算出所有 A-B ...
- Adatper中获取宽高为0的问题
但是我们想在getView()中获取ImageView的宽和高存在问题,在getView()里面刚开始显示item的时候利用ImageView.getWidth() 获取的都是0,为什么刚开始获取不到 ...
- IE8下提示'console'没有定义错误
在开发的过程中因为调试的原因,在代码中增加console.info("xxxx"),而未进行删除 在IE8下測试该代码所在的页面报错,例如以下: 须要注意的是,使用console对 ...
- C#-Mdi多文档窗体及其子窗体的排列 ---ShinePans
MdiLayout枚举成员及说明 Casecade s全部Mdi层叠在父窗体 TileHorizontal 水平平铺 TitleVertical 垂直平铺 Form1.cs (mdi) using S ...
- git学习 #2:git基本操作
本文出自 http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...
- [Redux] Persisting the State to the Local Storage
We will learn how to use store.subscribe() to efficiently persist some of the app’s state to localSt ...
- /proc/sys/ 下内核参数解析
http://blog.itpub.net/15480802/viewspace-753819/ http://blog.itpub.net/15480802/viewspace-753757/ ht ...
- [转] 学习React Native必看的几个开源项目
http://www.lcode.org/study-react-native-opensource-one/ http://gold.xitu.io/entry/575f498c128fe10057 ...
- 模拟dispatch_once
dispatch_once dispatch_once可以保证一段代码只被执行一次,因此出现之后使用最多的场景就是实现单例.本文来模拟实现dispatch_once的功能. 模拟dispatch_ ...