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. ...
随机推荐
- Is it possible to change the iPhone device name programmatically?
今天刚好方案公司谈到一个需求方案,要制作一个dvr连接手机,手机能上网的功能. 为了简化,让dvr开机轮询,连接某个iphone设备名字特征的手机,希望在app中提供一个输入框,可以 按dvr可以识别 ...
- 使用zipalign.exe工具优化APK安装包
zipalign.exe是Android自带的一个档案整理工具,它可以用于优化APK安装包,从而提升Android应用与系统之间的交互效率,提升应用程序的运行速度. 操作步骤: 1.在命令行窗口输入如 ...
- 设置win7任务栏显示标题,而不显示缩略图
win7系统的任务栏可以显示桌面缩略图,这是非常好的一个功能,但是有时候我们希望只显示标题,如下所示 怎样设置呢?只要在桌面上的计算机图标上面“右键”,选择“属性”,在弹出的窗口选择“高级系统设置”, ...
- Web前端开发:SQL Jsp小项目(一)
Jsp的学习算是告一段落,针对这段时间的学习,写了一个Jsp小项目来巩固学到的知识. 框架示意图 User list process UserAdd process 需要的界面效果: 需要工具:Ecl ...
- (转)C# 数据类型映射 (SQLite,MySQL,MSSQL,Oracle)
一.C# vs SQLite: C# SQLite 字段名 类型 库类型 GetFieldType(#) 转换 备注 F_BOOL bool BIT NOT NULL Boolean F_BOOL_N ...
- 【leetcode】9. Palindrome Number
题目描述: Determine whether an integer is a palindrome. Do this without extra space. 解题分析: ^_^个人觉得这道题没有什 ...
- NOIP2011(提高组)DAY2---观光公交(vijosP1741)
描述 风景迷人的小城Y市,拥有n个美丽的景点.由于慕名而来的游客越来越多,Y市特意安排了一辆观光公交车,为游客提供更便捷的交通服务.观光公交车在第0分钟出现在1号景点,随后依次前往2.3.4……n号景 ...
- Powerful Sleep(神奇的睡眠-睡眠生物钟的秘密:如何睡得更少却睡得更好)阅读笔记
睡眠机制 我们活着的时候,大脑会产生脑电波.脑电图仪器通过贴在人头上的一些电极读出脑电波的活动,然后把活动用图表显示出来. 睡眠过程可以分为5个过程,划分依据与大脑发出的脑电波类型. 当人清醒时,大脑 ...
- windows下redis 开机自启动
1,在redis的目录下执行(执行后就作为windows服务了) redis-server --service-install redis.windows.conf 2,安装好后需要手动启动redis ...
- 哆啦A梦连连看游戏源码完整版
这个源码是哆啦A梦连连看游戏源码完整版,也是安卓教程网android.662p.com分享过来的,哆啦A梦大家一定再熟悉不过了,这次登场的角色你能认出全部吗?赶紧把相同的小图标全部消除吧,一起体验下! ...