xtu summer individual 1 D - Round Numbers
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
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 解题:乱搞,找规律,毛线数位dp啊,搞死人
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
LL dp[] = {,,,,};
LL c[][];
void init() {
int i,j;
for(i = ; i <= ; i++) {
c[i][] = c[i][i] = ;
for(j = ; j < i; j++)
c[i][j] = c[i-][j-]+c[i-][j];
}
for(i = ; i <= ; i++){
for(j = ; j < i-j- ; j++)
dp[i] += c[i-][j];
dp[i] += dp[i-];
}
}
LL analysis(int x,int y,int base){
int i,j;
LL ans = ;
for(i = ; i+x <= base-i+y; i++)
ans += c[base][i];
return ans;
}
LL cal(int x) {
if(x == || x == ) return ;
int d[],i,len,one = ,zero = ;
LL ans = ;
for(len = ; x; x >>= ,len++) {
d[len] = x&;
}
ans += dp[len-];
one++;
for(i = len-; i > ; i--) {
if(d[i]) {
ans += analysis(one,zero+,i);
one++;
} else zero++;
}
if(d[]){
if(one == zero || one == zero+) ans += ;
else if(one < zero) ans += ;
one++;
}else zero++;
if(one >= && d[] == && one <= len - one) ans++;
return ans;
}
int main() {
init();
int a,b,i = ;;
while(~scanf("%d %d",&a,&b))
printf("%I64d\n",cal(b)-cal(a-));
return ;
}
xtu summer individual 1 D - Round Numbers的更多相关文章
- xtu summer individual 1 E - Palindromic Numbers
E - Palindromic Numbers Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %l ...
- 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
[BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...
- POJ 3252 Round Numbers
组合数学...(每做一题都是这么艰难) Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7607 A ...
- [BZOJ1662][POJ3252]Round Numbers
[POJ3252]Round Numbers 试题描述 The cows, as you know, have no fingers or thumbs and thus are unable to ...
- Round Numbers(组合数学)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10484 Accepted: 3831 Descri ...
- POJ 3252 Round Numbers(组合)
题目链接:http://poj.org/problem?id=3252 题意: 一个数的二进制表示中0的个数大于等于1的个数则称作Round Numbers.求区间[L,R]内的 Round Numb ...
- poj3252 Round Numbers
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7625 Accepted: 2625 Des ...
- bzoj1662: [Usaco2006 Nov]Round Numbers 圆环数
Description 正如你所知,奶牛们没有手指以至于不能玩“石头剪刀布”来任意地决定例如谁先挤奶的顺序.她们甚至也不能通过仍硬币的方式. 所以她们通过"round number" ...
- Round Numbers (排列组合)
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7558 Accepted: 2596 Description The c ...
随机推荐
- 解决Eclipse自动补全变量名的问题
原文地址: https://blog.csdn.net/czh500/article/details/53162157
- AJPFX总结集合的概念
//java 中集合的概述========================================================== 集合的概念: 为 ...
- 在git远程仓创建项目之后,提交本地项目的使用方法
命令介绍 git 用户配置 git config --global user.name "张三" git config --global user.email "zhag ...
- laravel模型关联
hasOne 一对一 用户名-手机号hasMany 一对多 文章-评论belongTo 一对多反向 评论-文章belongsToMany 多对多 用户-角色hasManyThrough 远程 ...
- ldap_modify: No such object (32) matched DN: cn=config
centos 6.9 部署 kerbors ldap 报错 [root@hadoop data]# ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ld ...
- Java中wait()方法为什么要放在同步块中?(lost wake-up 问题)
问题起源 事情得从一个多线程编程里面臭名昭著的问题"Lost wake-up problem"说起. 这个问题并不是说只在Java语言中会出现,而是会在所有的多线程环境下出现. 假 ...
- Microsoft Windows Server 部署
Microsoft Windows Server 部署 多重引导 计算机可以被设置多重引导,即在一台计算机上安装多个操作系统..在安装多重引导的操作系统时,还要注意版本的类型,一般应先安装版本低的,再 ...
- TUM好用的工具
https://vision.in.tum.de/data/datasets/rgbd-dataset/tools?tdsourcetag=s_pctim_aiomsg
- Spring-01 注解实现IOC
Spring框架四大原则 使用pojo进行轻量级和最小侵入式开发. 通过依赖注入和基于接口编程实现松耦合. 使用AOP和默认习惯进行声明式编程. 使用AOP和模板(template)减少模式化代码. ...
- mysql 根据月份查找数据