poj3252 Round Numbers(数位dp)
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 16439 | Accepted: 6776 |
Description
The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other names) in order to make arbitrary decisions such as who gets to be milked first. They can't even flip a coin because it's so hard to toss using hooves.
They have thus resorted to "round number" matching. The first cow picks an integer less than two billion. The second cow does the same. If the numbers are both "round numbers", the first cow wins,
otherwise the second cow wins.
A positive integer N is said to be a "round number" if the binary representation of N has as many or more zeroes than it has ones. For example, the integer 9, when written in binary form, is 1001. 1001 has two zeroes and two ones; thus, 9 is a round number. The integer 26 is 11010 in binary; since it has two zeroes and three ones, it is not a round number.
Obviously, it takes cows a while to convert numbers to binary, so the winner takes a while to determine. Bessie wants to cheat and thinks she can do that if she knows how many "round numbers" are in a given range.
Help her by writing a program that tells how many round numbers appear in the inclusive range given by the input (1 ≤ Start < Finish ≤ 2,000,000,000).
Input
Output
Sample Input
2 12
Sample Output
6
Source
#include<stdio.h>
#include<string.h>
typedef long long ll;
int n,m;
int dp[][][];//状态就是要记录二进制中0和1的数
int bit[];
ll dfs(int pos,int num0,int num1,bool lead,bool limit)
{
if(pos==-)return num0>=num1;
if(!limit&&!lead&&dp[pos][num0][num1]!=-)return dp[pos][num0][num1];
int up=limit?bit[pos]:;
ll ans=;
for(int i=;i<=up;i++)
{
ans+=dfs(pos-,(lead&&i==)?:num0+(i==),(lead&&i==)?:num1+(i==),lead&&i==,limit&&i==bit[pos]);
}
if(!limit&&!lead)dp[pos][num0][num1]=ans;
return ans;
}
ll solve(ll x)
{
int len=;
while(x)
{
bit[len++]=x&;
x>>=;
}
return dfs(len-,,,,);
}
int main()
{
memset(dp,-,sizeof(dp));
scanf("%d %d",&n,&m);
printf("%lld\n",solve(m)-solve(n-));
}
poj3252 Round Numbers(数位dp)的更多相关文章
- POJ3252 Round Numbers —— 数位DP
题目链接:http://poj.org/problem?id=3252 Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Su ...
- poj3252 Round Numbers (数位dp)
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- poj3252 Round Numbers[数位DP]
地址 拆成2进制位做dp记搜就行了,带一下前导0,将0和1的个数带到状态里面,每种0和1的个数讨论一下,累加即可. WA记录:line29. #include<iostream> #inc ...
- 【poj3252】 Round Numbers (数位DP+记忆化DFS)
题目大意:给你一个区间$[l,r]$,求在该区间内有多少整数在二进制下$0$的数量$≥1$的数量.数据范围$1≤l,r≤2*10^{9}$. 第一次用记忆化dfs写数位dp,感觉神清气爽~(原谅我这个 ...
- [poj3252]Round Numbers_数位dp
Round Numbers poj3252 题目大意:求一段区间内Round Numbers的个数. 注释:如果一个数的二进制表示中0的个数不少于1的个数,我们就说这个数是Round Number.给 ...
- poj 3252 Round Numbers(数位dp 处理前导零)
Description The cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, P ...
- 4-圆数Round Numbers(数位dp)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14947 Accepted: 6023 De ...
- POJ 3252 Round Numbers(数位dp&记忆化搜索)
题目链接:[kuangbin带你飞]专题十五 数位DP E - Round Numbers 题意 给定区间.求转化为二进制后当中0比1多或相等的数字的个数. 思路 将数字转化为二进制进行数位dp,由于 ...
- POJ - 3252 - Round Numbers(数位DP)
链接: https://vjudge.net/problem/POJ-3252 题意: The cows, as you know, have no fingers or thumbs and thu ...
- Round Numbers(数位DP)
Round Numbers http://poj.org/problem?id=3252 Time Limit: 2000MS Memory Limit: 65536K Total Submiss ...
随机推荐
- JavaScript中的柯里化
转载自:https://www.cnblogs.com/zztt/p/4142891.html 何为Curry化/柯里化? curry化来源与数学家 Haskell Curry的名字 (编程语言 Ha ...
- 2018-2-13-WPF-延迟加载
title author date CreateTime categories WPF 延迟加载 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23:3 + ...
- BJSV-P-004无缝大屏显示
无缝大屏显示 北京太速科技有限公司在线客服:QQ:448468544 淘宝网站:orihard.taobao.com/?联系电话:15084122580 欢迎关注微信公众号 啊智能时代
- django 常用 import
from django.shortcuts import HttpResponse, render, redirect def yimi(request): #直接返回页面内容 return Http ...
- HTML基础 块级元素和内联元素
大多数 HTML 元素被定义为块级元素或内联元素. 块级元素包括:body from select textarea h1-h6 html table button hr p ol ...
- jmeter 参数化5_Count 计数器
如果需要引用的数据量较大,且要求不能重复或者需要自增,那么可以使用计数器来实现. 计数器(counter):允许用户创建一个在线程组之内都可以被引用的计数器. 计数器允许用户配置一个起点,一个最大值, ...
- FreeBSD虚拟机——小折腾
最近,突然想起来Linux了,因为前段时间接触了DOS命令,提高了自己的工作效率,这会想再温习下Linux的CLI,无奈windows下unix命令,水土不服,因此想尝试虚拟机,虚拟机软件无非vmwa ...
- vmware版本选择
vmware哪个版本好用 2014-03-10 22:59一枚小白3 | 分类:常见软件 | 浏览6743次 准备装ghost xp,想问下哪个版本更适合?或者现在哪个版本更稳定,求不要复制,求大神解 ...
- struts2的作用是什么
struts2是一种重量级的框架,位于MVC架构中的controller,可以分析出来,它是用于接受页面信息然后通过内部处理,将结果返回. 同时struts2也是一个web层的MVC框架,那么什么是s ...
- AshMap如何让hash保持一致
学Java的都知道hashMap的底层是“链表散列”的数据结构也也可以说是hash表.在put的实话先根据key的hashcode重新计算hash值的,而我们又知道hash是一种算法.所以哈希码并不是 ...