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 ...
随机推荐
- 转 OGG Troubleshooting-Database error 1 (ORA-00001: unique constraint ...)
Q5: After imp data to target, when we start replc process, we find the following error: 2011-11-10 0 ...
- HAL之定时器
一首先得对定时器的时钟与系统时钟的关系搞清楚,基本定时器的时钟来自APB1最大36MHZ.(定时器倍频值为1) 二 在STM32CubeMX中打开外设功能,时钟源选择内部:然后在配置定时器3中的参数设 ...
- CentOS Linux下MySQL 5.1.x的安装、优化和安全配置
下载页面:http://dev.mysql.com/downloads/mysql/5.1.html#downloads 到页面底部,找到Source downloads,这个是源码版本,下载第1个T ...
- 由浅入深一个Demo带你认识Restful风格的架构
java作为一门后端语言,其厉害之处在于web,大家比较熟知的各种网络应用,java都能做,那么在这个移动优先的时代,如何继续发挥java的强大之处呢? 通常是让java作为一个app的服务端,为ap ...
- 关于IE 对 $.get 缓存的记录
最近在IE9中碰到一个问题是, 当我对某个角色进行修改的时候,再点击查询还是修改之前的内容,但是实际数据库已经修改成功,纠结了好一会儿之后,才发现是 $.get请求的问题. 因为 IE对get请求, ...
- java 自定义注解,并使用示例
场景: 对需要校验 手机验证码和短信验证码的controller方法添加 自定义的注解 @CheckType 1. 定义注解 /** * 需要短信.验证码验证方法上的注解 * date: 2018年 ...
- JS进阶-闭包的几种常见形式
作用域链: //作用域链 var a = 1; function test() { var b =2; return a; } alert(test());//弹出1: alert(b);//不能获取 ...
- web前端工程师入门须知
本文是写给那些想要入门web前端工程的初学者,高手请路过,也欢迎高手们拍砖. 先说下web前端工程师的价值,目前web产品交互越来越复杂,用户使用体验和网站前端性能优化这些都得靠web前端工程师去做w ...
- Python100天打卡-Day10-图形用户界面和游戏开发
基于tkinter模块的GUIPython默认的GUI开发模块是tkinter(在Python 3以前的版本中名为Tkinter)使用tkinter来开发GUI应用需要以下5个步骤: 导入tkinte ...
- mysql登录(linux)
一.修改配置文件 查询路径 find / -name my.cnf 修改文件 vi my.cnf [mysqld]下面加上skip-grant-tables 二.登录数据库 重启mysql servi ...