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 ...
随机推荐
- Alt+数字 输入特殊字符
前言: 按住Alt键不放,再按(小键盘的)数字键,然后放开就可以输入特殊字符. 起始 终止 字符类别 0 255 基本与ASCII 码表对应 42657 42680 大写希腊字母 ...
- Mysql选择合适的存储引擎
Myisam:默认的mysql插件式存储引擎.如果应用是以读操作和插入操作为主,只有很少的更新和删除操作,并且对事务的完整性.并发性要求不是很高,那么选择这个存储引擎是非常合适的.Myisam是在we ...
- 生产环境中nginx既做web服务又做反向代理
一.写对于初入博客园的感想 众所周知,nginx是一个高性能的HTTP和反向代理服务器,在以前工作中要么实现http要么做反向代理或者负载均衡.尚未在同一台nginx或者集群上同时既实现HTTP又实现 ...
- js去掉数组的空字符串
后台返回数据的时候,有些数据为空时,一般都不进行显示,需要去除空字符串. 基本思路:获取数组张度,遍历数组,当数组某个值等于‘’或null或数据类型为undefined时,根据splice方法去除数据 ...
- 分层开发之C#分层
假如没有用分层开发,仔细分析三人的开发过程,很容易发现其中的问题: >三人排队式的轮番工作,花费的时间是三人工作时间之和. >后面开发的人基本都是要先花费时间熟悉前面人的代码,否则开发难以 ...
- laravel 权限管理 常用命令
use Spatie\Permission\Models\Role;use Spatie\Permission\Models\Permission; $role = Role::create(['na ...
- JS内置对象练习(慕课网题目)
效果图: XXXX年XX月X日 星期X--班级总分为:81 格式要求: 1.显示打印的日期. 格式为类似“XXXX年XX月XX日 星期X” 的当前的时间. 2.计算出该班级的平均分(保留整数). 同学 ...
- COGS 942. [東方S3] 比那名居天子
Problem 1 比那名居天子(tenshi.cpp/c/pas) 题目描述 在幻想乡,比那名居天子是管理着『要石』的天人.『要石』是能够引发和镇压地震的存在,当然也可以用来改变地形.因为在幻想乡引 ...
- macos openssl 生成rsa证书 -mark
创建私钥 openssl genrsa -out rsa_private_key.pem 1024 创建无密码私钥 openssl pkcs8 -topk8 -inform PEM –nocrypt ...
- springboot设置接口超时
springboot 设置接口超时 1.配置文件 application.properties中加了,意思是设置超时时间为20000ms即20s, spring.mvc.async.request-t ...