可以推出规律  每一个数第一次出现的位置 和 n*10后出现的位置  要特殊考虑 是10的倍数的情况(10,100,1000, .......) 它的位置是不会改变的

#include<cstdio>
#define uLL unsigned long long
using namespace std;
uLL a[30] = {}, b[30] = {1,10};
void init()
{
for(int i = 1; i <= 20; ++i)
a[i] = a[i-1]*10 + 1;
for(int i = 2; i <= 20; ++i)
b[i] = b[i-1]*10;
} uLL fn(uLL n, uLL k)
{
uLL i = 0;
while(n >= 10)
{
i += (n%10)*a[k++] + 1;
n /= 10;
}
return i+(n-1)*a[k]+1;
} int findd(uLL n)
{
int i = 0;
while(n >= 10)
{
i++;
n /= 10;
}
return i;
}
int main()
{
init();
uLL n,m,k;
scanf("%I64u%I64u",&n,&m);
uLL d = findd(n);
if(fn(n, 1) > m)
{
puts("0");
return 0;
}
if(fn(n, 1) == (d+1))
{
if(fn(n, 1) == m)
printf("%I64u", n);
else
puts("0");
return 0;
}
else
{
k = 1;
while(fn(n, k) <= m)
k++;
if(m == fn(n, k-1))
{
if(k > 2)
printf("%I64u", b[k-2]*n-1);
else
printf("%I64u", b[k-2]*n);
}
else
printf("%I64u", m-fn(n, k-1) + b[k-1]*b[d]-1);
}
return 0;
}

ural 1233的更多相关文章

  1. URAL 1233 Amusing Numbers 好题

    参照了nocow上的解法,照搬过来…… 易知一个数X在数列中在另一个数Y前,当且仅当X前缀小于Y或前缀相等X短,那么我们分布考虑,比如对于数48561: 5位上:10000~48560; 4位上:10 ...

  2. URAL 1233 - Amusing Numbers

    首先计算出k至少为第几位,如果m小于这个数,那么输出0 还有一种情况, 就是10的i次方的这种情况,如果i+1等于m,那么直接输出k,否则输出0 其他的情况,就是二分,然后判断计算其插入到k之前的数的 ...

  3. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  4. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  5. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  6. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  7. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  8. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

  9. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

随机推荐

  1. 每天一道LeetCode--169.Majority Elemen

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  2. Win7 IIS (HTTP Error 500.21 - Internal Server Error)解决

    今天在测试网站的时候,在浏览器中输入http://localhost/时,发生如下错误: HTTP Error 500.21 - Internal Server Error Handler " ...

  3. html保留字符详解

    本文由 www.169it.com 搜集整理 1. 注释 HTML中的注释和其它语言注释作用相似,都是为了方便阅读和调试代码.当浏览器遇到注释时会自动忽略注释内容.HTML的注释格式多行和单行注释都用 ...

  4. Contoso 大学 - 6 – 更新关联数据

    原文 Contoso 大学 - 6 – 更新关联数据 By Tom Dykstra, Tom Dykstra is a Senior Programming Writer on Microsoft's ...

  5. ASP.NET下运用Memcached

    对于大型网站的高并发,在ASP.NET网站下的session性能并不高,所以造成人们一种印象,大型WEB项目使用JAVA的错觉,致使很多人吐槽微 软不给力,其实这好比拉不出怪地球引力,本文介绍Memc ...

  6. Cocos移植到Android-使用Eclipse交叉编译打包

    如果对命令行望而生畏,我们可以借助于安装有ADT插件的Eclipse工具实现交叉编译.使用Eclipse进行交叉编译,首先需要将要编译的工程导入到Eclipse的Workspace中,Workspac ...

  7. iOS夯实:内存管理

    iOS夯实:内存管理 文章转自 内存管理 最近的学习计划是将iOS的机制原理好好重新打磨学习一下,总结和加入自己的思考. 有不正确的地方,多多指正. 目录: 基本信息 旧时代的细节 新时代 基本信息 ...

  8. 在button中加入一个view图片

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...

  9. C#中实现抽象类里建立静态方法

    这篇文章主要介绍了C#中实现抽象类里建立静态方法,需要的朋友可以参考下   本文简述了C#中实现抽象类里建立静态方法的解决办法,示例程序如下: 1 2 3 4 5 6 public class Tes ...

  10. Using LINQ Group By and String.Join() / Aggregate() in Entity Framework 3.5

    linq to sql 的时候,有时候需要用到 先group  然后来个 aggregate 串连一下值, 但会总会出错,说不识别 aggregate 或者 string.join 方法 搜遍网络 一 ...