ural 1233
可以推出规律 每一个数第一次出现的位置 和 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的更多相关文章
- URAL 1233 Amusing Numbers 好题
参照了nocow上的解法,照搬过来…… 易知一个数X在数列中在另一个数Y前,当且仅当X前缀小于Y或前缀相等X短,那么我们分布考虑,比如对于数48561: 5位上:10000~48560; 4位上:10 ...
- URAL 1233 - Amusing Numbers
首先计算出k至少为第几位,如果m小于这个数,那么输出0 还有一种情况, 就是10的i次方的这种情况,如果i+1等于m,那么直接输出k,否则输出0 其他的情况,就是二分,然后判断计算其插入到k之前的数的 ...
- 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome
题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- ural 2073. Log Files
2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...
- ural 2070. Interesting Numbers
2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...
- ural 2069. Hard Rock
2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...
- 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 ...
- ural 2067. Friends and Berries
2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...
随机推荐
- Android之触屏事件
方法一: 新建"MyView"类 package onTouchEvent; import android.content.Context; import android.grap ...
- JAVA之数据溢出
Integer在java中属于包装类,既能用于字符串与整型的转换,也能用于拆箱与装箱 package ABC; public class A{ public static void main(Stri ...
- CentOS安装Node.js简单教程
记录一下自己安装过程 先安装gcc-c++编译环境和openssl 代码如下 复制代码 yum install gcc-c++ openssl-devel wget http://nodejs.or ...
- 译:Spring框架参考文档之IoC容器(未完成)
6. IoC容器 6.1 Spring IoC容器和bean介绍 这一章节介绍了Spring框架的控制反转(IoC)实现的原理.IoC也被称作依赖注入(DI).It is a process wher ...
- Yii Framework处理网站前后台文件的方法
此方法参考官方网站的cookbook,详细请看http://www.yiiframework.com/doc/cookbook/33/, 我在此基础上做了一些改动,人个感觉非常棒了,大家可以试一下! ...
- (转)理想化的 Redis 集群
一个豁达的关键是正确乐观的面对失败的系统.不需要过多的担心,需要一种去说那又怎样的能力.因此架构的设计是如此的重要.许多优秀的系统没有进一步成长的能力,我们应该做的是去使用其他的系统去共同分担工作. ...
- php提取字符串中的数字
最近工作中写代码的时候需要在一串字符串中将所有的数字提取出来这么一个小功能,研究了一下发现方法还挺多,值得记录一下,于是对如何使用PHP将字符串中的数字提取出来的功能做了一个小总结,总结三种方法如下: ...
- CentOS安装libpcap
1.安装GCC: yum -y install gcc-c++ 2.安装flex: yum -y install flex 没有flex,直接安装libpcap会提示"Your o ...
- git命令行
cmd下运行或者 进入git bash运行 输入 exit退出切换到仓库目录后再git statusgit commit -m 注释 git pull origin1 mastergit push o ...
- Can’t create handler inside thread that has not called Looper.prepare()
1)在Android 2.3以前,为防止ANR(Application Not Responding),Google是不赞成将网络连接等一系列耗时操作直接放到应用主线程进行的,推荐将这类操作放在子线程 ...