TOJ1688: Round Numbers

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

Line 1: Two space-separated integers, respectively Start and Finish.

Output

Line 1: A single integer that is the count of round numbers in the inclusive range Start..Finish

Sample Input

2 12

Sample Output

6

Source

USACO November 2006

0的个数进行dp

#include<bits/stdc++.h>
using namespace std;
int dp[][],a[],l,r;
int dfs(int pos,int st,int pre,int lim)
{
if(pos<)return st<=;
if(!lim&&!pre&&dp[pos][st]!=-)return dp[pos][st];
int mi=lim?a[pos]:,ans=;
for(int i=;i<=mi;i++)
if(pre&&!i)ans+=dfs(pos-,st,,lim&&i==a[pos]);
else ans+=dfs(pos-,i?st+:st-,,lim&&i==a[pos]);
if(!lim&&!pre)dp[pos][st]=ans;
return ans;
}
int la(int x)
{
int tot=;
while(x)a[tot++]=x&,x>>=;
return dfs(tot-,,,);
}
int main()
{
memset(dp,-,sizeof dp);
scanf("%d%d",&l,&r);
printf("%d\n",la(r)-la(l-));
return ;
}

不要62

HDU - 2089

杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。 
杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。 
不吉利的数字为所有含有4或62的号码。例如: 
62315 73418 88914 
都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。 
你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。 

Input输入的都是整数对n、m(0<n≤m<1000000),如果遇到都是0的整数对,则输入结束。 
Output对于每个整数对,输出一个不含有不吉利数字的统计个数,该数值占一行位置。 
Sample Input

1 100
0 0

Sample Output

80

很简单的数位dp

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define pll pair<long long,long long>
#define pii pair<int,int>
#define pq priority_queue
const int N=,MD=1e9+,INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-,e=exp(),PI=acos(-.);
int c[N],dp[N][];
int dfs(int pos,int st,int pre,int lim)
{
if(pos<)return ;
if(!lim&&dp[pos][st]!=-)return dp[pos][st];
int last=lim?c[pos]:,ans=;
for(int i=; i<=last; i++)
if(pre==&&i==||i==)continue;
else ans+=dfs(pos-,i==,i,lim&&(i==last));
if(!lim)dp[pos][st]=ans;
return ans;
}
int slove(int q)
{
int cnt=;
while(q)c[cnt++]=q%,q/=;
return dfs(cnt-,,-,);
}
int main()
{
ios::sync_with_stdio(false),cin.tie(),cout.tie();
int x,y;
while(cin>>x>>y,x+y)
{
memset(dp,-,sizeof dp);
cout<<slove(y)-slove(x-)<<"\n";
}
return ;
}

Amount of Degrees

URAL - 1057

Create a code to determine the amount of integers, lying in the set [ XY] and being a sum of exactly K different integer degrees of B.
Example. Let X=15, Y=20, K=2, B=2. By this example 3 numbers are the sum of exactly two integer degrees of number 2:
17 = 2 4+2 0
18 = 2 4+2 1
20 = 2 4+2 2.

Input

The first line of input contains integers X and Y, separated with a space (1 ≤ X ≤  Y ≤ 2 31−1). The next two lines contain integers K and B (1 ≤ K ≤ 20; 2 ≤  B ≤ 10).

Output

Output should contain a single integer — the amount of integers, lying between Xand Y, being a sum of exactly K different integer degrees of B.

Example

input output
15 20
2
2
3

也不难吧,论文题里的模板题

#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lson l,(l+r)/2,rt<<1
#define rson (l+r)/2+1,r,rt<<1|1
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define pll pair<long long,long long>
#define pii pair<int,int>
#define pq priority_queue
const int N=,MD=1e9+,INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const double eps=1e-,e=exp(),PI=acos(-.);
int c[N],dp[N][N];
int x,y,k,b;
int dfs(int pos,int st,int lim)
{
if(st>k||st+pos+<k)return ;
if(pos<)return st==k;
if(!lim&&dp[pos][st]!=-)return dp[pos][st];
int last=lim?c[pos]:b-,ans=,mi=min(last,);
for(int i=;i<=mi;i++)ans+=dfs(pos-,st+i,lim&&(i==last));
if(!lim)dp[pos][st]=ans;
return ans;
}
int slove(int q)
{
int cnt=;
while(q)c[cnt++]=q%b,q/=b;
return dfs(cnt-,,);
}
int main()
{
ios::sync_with_stdio(false),cin.tie(),cout.tie();
cin>>x>>y>>k>>b;
memset(dp,-,sizeof dp);
cout<<slove(y)-slove(x-);
return ;
}

上海邀请赛的

链接:https://www.nowcoder.com/acm/contest/163/J
来源:牛客网

Beautiful Numbers
时间限制:C/C++ 8秒,其他语言16秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

NIBGNAUK is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if and only if it is divisible by the sum of its digits.

We will not argue with this and just count the quantity of beautiful numbers from 1 to N.

输入描述:

The first line of the input is T(1≤ T ≤ 100), which stands for the number of test cases you need to solve.
Each test case contains a line with a positive integer N (1 ≤ N ≤ 10

12

).

输出描述:

For each test case, print the case number and the quantity of beautiful numbers in [1, N].

输入例子:
2
10
18
输出例子:
Case 1: 10
Case 2: 12

-->

示例1

输入

复制

2
10
18

输出

复制

Case 1: 10
Case 2: 12

很难想到从数位和出发

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[];
ll dp[][][][],n;
ll dfs(int pos,int st,int sum,int mod,bool lim)
{
if(pos<) return mod==&&st==sum;
if(sum>st||sum+*(pos+)<st)return ;
if(!lim&&dp[st][pos][sum][mod]>=) return dp[st][pos][sum][mod];
ll ans=;
int mi=lim?a[pos]:;
for(int i=;i<=mi;i++)ans+=dfs(pos-,st,sum+i,(mod*+i)%st,lim&&i==mi);
if(!lim) dp[st][pos][sum][mod]=ans;
return ans;
}
ll cal(ll n)
{
int pos=;
while(n) a[pos++]=n%,n/=;
ll ans=;
for(int i=;i<=;i++)ans+=dfs(pos-,i,,,);
return ans;
}
int main()
{
int T,ca=;
memset(dp,-,sizeof(dp));
scanf("%d",&T);
while(T--)scanf("%lld",&n),printf("Case %d: %lld\n",++ca,cal(n));
return ;
}

以前刷过的数位dp的更多相关文章

  1. HDU5787 K-wolf Number 数位dp

    分析:赛场上也知道是裸的数位dp,但是无奈刷数位dp题刷的太少了,并不能写出来 一点感想:赛后补题,看了题解的map记录状态,一脸蒙逼,也是非常的不爽,然后想看别人写的,不是递归就是写的比较乱 而且我 ...

  2. 数位DP专题

    这周开始刷数位DP,在网上找到一份神级数位DP模板,做起题目来爽歪歪. http://www.cnblogs.com/jffifa/archive/2012/08/17/2644847.html in ...

  3. 数位DP入门Ural1057

    CF一战让我觉得很疲倦,所以今天感觉很慢. 昨天解D题时候,因为太累,根本连题目都没看,今天看了之后感觉不会做,听闻是数位DP问题. 有某神说过,DP的功力建立在刷过的题上,我真的毫无功力可言. 介绍 ...

  4. 数位dp整理

    数位dp的思想就在于递归,记录当前的某一个唯一状态,依次递归下去,要注意唯一. 数位dp常设的状态有当前位置,上一数字,是否具有前导零,是否有限制. 1.CodeForces 55DBeautiful ...

  5. hihoCoder #1770 : 单调数(数位dp)

    题面 我们定义一个数是单调数,当且仅当构成这个数每一个数位都是单调不降或不增的. 例如 \(123\) 和 \(321\) 和 \(221\) 和 \(111\) 是单调的,而 \(312\) 不是单 ...

  6. 数位dp小练

    最近刷题的同时还得填填坑,说来你们也不信,我还不会数位dp. 照例推几篇博客: 数位DP讲解 数位dp 的简单入门 这两篇博客讲的都很好,不过代码推荐记搜的形式,不仅易于理解,还短. 数位dp的式子一 ...

  7. 数位DP复习小结

    转载请注明原文地址http://www.cnblogs.com/LadyLex/p/8490222.html 之前学数位dp的时候底子没打扎实 虚的要死 这次正好有时间……刷了刷之前没做的题目 感觉自 ...

  8. 【数位DP】【SCOI2009】windy数

    传送门 Description \(windy\)定义了一种\(windy\)数.不含前导零且相邻两个数字之差至少为\(2\)的正整数被称为\(windy\)数.\(windy\)想知道, 在\(A\ ...

  9. [Bzoj4521][Cqoi2016]手机号码(数位dp)

    4521: [Cqoi2016]手机号码 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 870  Solved: 505[Submit][Status ...

随机推荐

  1. 对Yii 2.0模型rules的理解(load()无法正确装载数据)

    在实际开发中,遇到数据表新增字段而忘记了在对应模型中rules规则中添加新增的字段,而导致load()方法装载不到新增字段,导致新增字段无法写入数据库中.   解决办法:在新增字段后及时在对应模型ru ...

  2. xmlHttpRequest在Firefox下不起作用?

    描述: XMLHttpRequest 在IE下正常,在Firefox下不起作用. 原因: XMLHttpRequest 对象的 onreadystatechange 不会在Firefox下执行, 解放 ...

  3. SAP Cloud for Customer的Account Team里的role如何配置

    Account Team标签页里点击Add按钮: 这些下拉菜单里的role在哪里配置? 在business configuration工作中心:Implementation projects-> ...

  4. Netweaver和SAP云平台的quota管理

    Netweaver 以需要为一个用户上下文(User Context)能够在SAP extended memory区域中分配内存尺寸创建quota为例. 对于Dialog工作进程,使用事务码修改参数 ...

  5. ansible 任务委派 delegate_to

    ansible 任务委派功能delegate_to run_noce: true  在一个主机上面只执行一次一个任务. ,如果没有这个参数的话,每个playbook中的组的主机都会执行一次. 我们有的 ...

  6. ECshop安装提示cls_image::gd_version() 和不支持JPEG

    ecshop版本:ECShop_V2.7.3_UTF8_release1106php 版本 5.5--------------------------------------------------- ...

  7. 2018.4.15 Mac系统下如何使用StartUml画好需求分析的类图 (同样适用于windows)

    Mac如何使用StartUml (同样适用于windows) 左侧边栏的英文含义及其用法 关联(Association) [关联关系]:是一种拥有的关系,它使一个类知道另一个类的属性和方法:如:老师与 ...

  8. 计算机应用第三次作业:自动开机自动关机 常用DOS命令 关于文件文件夹

    一.自动开机 台式机启动时按住DEL键 进入一个蓝色的界面,界面上是英文提示 这个界面是BIOS  ,是在机器的ROM中存储 二.自动关机 自动重启 方法一在120秒钟后自动关机 win+r (RUN ...

  9. linux下libnet编程 亲自测试可用

    linux下libnet编程 亲自测试可用 亲自测试  如果build包的时候 只要把类型改了 就能改成相应的协议. 0x0800 ip 0x0806 arp 0x86DD    IPv6 0x86e ...

  10. Tarjan算法 详解+心得

    Tarjan算法是由Robert Tarjan(罗伯特·塔扬,不知有几位大神读对过这个名字) 发明的求有向图中强连通分量的算法. 预备知识:有向图,强连通. 有向图:由有向边的构成的图.需要注意的是这 ...