1057

简单的数位DP  刚开始全以2进制来算的 后来发现要找最接近x,y值的那个基于b进制的0,1组合

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cmath>
using namespace std;
#define LL __int64
#define INF 1e11
LL dp[][],pp[][];
int g1,g2,p[<<];
void init()
{
int i,j;
for(i = ; i <= ; i++)
{
pp[i][] = ;
for(j = ; j <= ; j++)
{
pp[i][j] = pp[i][j-]*i;
if(pp[i][j]>INF)
break;
}
}
dp[][] = ;
dp[][] = ;
dp[][] = ;
for(i = ; i <= ; i++)
{
dp[i][] = ;
for(j =; j <= ; j++)
dp[i][j] = dp[i-][j-]+dp[i-][j];
}
}
void change(int x,int y,int b,int c1[],int c2[])
{
int di[],g=,i;
while(x)
{
di[++g] = x%b;
x/=b;
}
for(i = g ; i >= ;i--)
c1[i] = di[i];
g1 = g;
g = ;
while(y)
{
di[++g] = y%b;
y/=b;
}
for(i = g ; i >= ;i--)
c2[i] = di[i];
g2 = g;
}
LL find(int c[],int k,int len)
{
int i,j,o=;
LL sum=;
for(i = len ; i >= ; i--)
{
if(c[i]==) continue;
if(k>=o)
sum+=dp[i-][k-o];
o++;
}
if(o==k)
sum++;
return sum;
}
int main()
{
int x,y,k,b,j,i;
int c1[],c2[];
init();
scanf("%d%d%d%d",&x,&y,&k,&b);
if(b!=)
{
LL s=,x1=-,x2=-;
x--;
for(i = ; i <= (<<) ; i++)
{
s = ;
for(j = ; j <= ; j++)
if(i&(<<j))
{
s+=pp[b][j];
}
if(x1==-&&s>x)
x1 = i-;
if(s>y)
{
x2 = i-;
break;
}
}
for(j = ; j >= ; j--)
if(x1&(<<j))
{
c1[j+] = ;
if(!g1)
g1 = j+;
}
else
c1[j+] = ;
for(j = ; j >= ; j--)
if(x2&(<<j))
{
c2[j+] = ;
if(!g2)
g2 = j+;
}
else
c2[j+] = ;
}
else
change(x-,y,b,c1,c2);
LL s1 = find(c1,k,g1);
LL s2 = find(c2,k,g2);
printf("%I64d\n",s2-s1);
return ;
}

URAL1057. Amount of Degrees(DP)的更多相关文章

  1. Ural1057. Amount of Degrees 题解 数位DP

    题目链接: (请自行百度进Ural然后查看题号为1057的那道题目囧~) 题目大意: Create a code to determine the amount of integers, lying ...

  2. [ural1057][Amount of Degrees] (数位dp+进制模型)

    Discription Create a code to determine the amount of integers, lying in the set [X; Y] and being a s ...

  3. Ural1057 - Amount of Degrees(数位DP)

    题目大意 求给定区间[X,Y]中满足下列条件的整数个数:这个数恰好等于K个互不相等的B的整数次幂之和.例如,设X=15,Y=20,K=2,B=2,则有且仅有下列三个数满足题意: 输入:第一行包含两个整 ...

  4. ural1057 Amount of Degrees

    链接 这题有一点小坑点 就是AX^B  A只能为0或者1  ,剩下的就比较好做的了. #include <iostream> #include<cstdio> #include ...

  5. ural1057 Amount of degrees 位数统计

    #include <iostream> #include <string> using namespace std; ][]; void init(){ f[][] =; ;i ...

  6. Timus Online Judge 1057. Amount of Degrees(数位dp)

    1057. Amount of Degrees Time limit: 1.0 second Memory limit: 64 MB Create a code to determine the am ...

  7. Ural Amount of Degrees(数位dp)

    传送门 Amount of Degrees Time limit: 1.0 secondMemory limit: 64 MB Description Create a code to determi ...

  8. [TimusOJ1057]Amount of Degrees

    [TimusOJ1057]Amount of Degrees 试题描述 Create a code to determine the amount of integers, lying in the ...

  9. 一本通1585【例 1】Amount of Degrees

    1585: [例 1]Amount of Degrees 时间限制: 1000 ms         内存限制: 524288 KB 题目描述 原题来自:NEERC 2000 Central Subr ...

随机推荐

  1. 服务端 unity

    第一个问题 https://www.google.com.hk/search?q=internal+inconsistency+looking+up+disk+image+%27vm+disk+2%2 ...

  2. ie 与 Chrome 时间格式化问题.

    ie 与 Chrome 时间格式化通用: new Date(res[i].Time.replaceAll("-", "/")).format("yyy ...

  3. C编译错误解决方法

    1.expected identifier before numeric constant 一般情况下是枚举类型中的某个变量已经被#define定义过一次了,在项目空间中搜索你枚举类型中的所有变量类型 ...

  4. How Big Is A Petabyte, Exabyte, Zettabyte, Or A Yottabyte?

    一个关于Byte递增的描述,蛮有趣的! Bytes -> Kilobyte -> Megabyte -> Gigabyte -> Terabyte -> Petabyte ...

  5. Java package详解

    Java引入包(package)机制,提供了类的多层命名空间,用于解决类的命名冲突.类文件管理等问题.Java允许将一组功能相关的类放在同一个package下,从而组成逻辑上的类库单元.如果希望把一个 ...

  6. Asp.net最基本的文件上传功能代码

    aspx前台页面代码 <form id="form1" action="File.aspx" runat="server" encty ...

  7. kafka配置

    官网:http://kafka.apache.org/ 主要有3种安装方式: 1. 单机单broker 2. 单机多broker 3. 多机多broker 1. wget http://mirror. ...

  8. hdu 4768 Flyer 二分

    思路:由于最多只有一个是奇数,所以二分枚举这个点,每次判断这个点的左边区间段所有点的和作为 二分的依据. 代码如下: #include<iostream> #include<cstd ...

  9. jmeter 异步子请求测试随笔

    好久没写技术类的博客了,都不知道自己都在忙啥.... 最近陆续遇到了一些异步子请求的测试需求,比如打开某一个页面A,A页面里的js会再调用B,C,D,E等请求,针对这个页面的测试,我最近做了一些思考: ...

  10. Spring框架学习之第1节

    spring快速入门 ①   spring是什么? Struts是web框架(jsp/action/actionform) hibernate是orm框架(对象和关系映射框架),处于持久层 sprin ...