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. ...
随机推荐
- ASP.NET中页面加载时文本框(texbox控件)内有文字获得焦点时文字消失
代码如下: <asp:TextBox ID="TextBox1" runat="server" Height="26px" MaxLe ...
- SQL Server 中WITH (NOLOCK)浅析(转潇湘隐者)
博文出处:http://www.cnblogs.com/kerrycode/p/3946268.html 概念介绍 开发人员喜欢在SQL脚本中使用WITH(NOLOCK), WITH(NOLOCK)其 ...
- DayDream, 移动VR 2.0里程碑: 概述(上篇)
VR设备, 断断续续使用了很多个; 尤其是最近半年,主要是PC VR方面项目. 以前对移动VR不感冒,这几天试用了一下DayDream, 眼前突然一亮, 就如同年初首次使用HTC Vive眼前一亮的感 ...
- ios 一个app启动另一个app
问题描述:需要从一个ios应用程序中,能启动另一个ios应用程序. 开发环境:xcode7.3.1 关键词:白名单(LSApplicationQueriesSchemes).注册自己的URL Demo ...
- 【leetcode】354. Russian Doll Envelopes
题目描述: You have a number of envelopes with widths and heights given as a pair of integers (w, h). One ...
- Adobe Dreamweaver CS6 序列号 注册码(转自91zcm)
Adobe Dreamweaver CS6 序列号 注册码: 1192-1632-4987-2281-1039-4334 1192-1697-0848-9963-2161-72481192-1871 ...
- jquery实现全选、全不选、反选操作
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- jQuery学习教程(3)
一.什么是DOM操作? 文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言的标准编程接口.在网页上,组织页面(或文档)的对象被组织在一个树形结 ...
- MySQL查询LIKE如何匹配下划线 通配符转义
MySQL查询时使用LIKE匹配下划线,您会发现连查询“%A_B%”时会出现“%A B%”和“%AB%”也查询出来了,这是因为下划线也被当作特殊字符,做了任意匹配转换了,所以,要想匹配下划线,那么就需 ...
- 帝国cms中 内容分页的SEO优化
关于内容页如果存在分页的话,我们想区分第一页和后面数页,当前的通用做法是在标题上加入分页码,帝国cms中如何做到呢.我们可以修改在e/class/functions.php中的源码.找到找到GetHt ...