Problem H. Hotel in Ves Lagos
Problem H. Hotel in Ves Lagos
Input le: hotel.in
Output le: hotel.out
Time limit: 1 second
Memory limit: 256 megabytes
A new hotel is being built in the city of Ves Lagos. The hotel will have an innite number of rooms (it is out of fashion to build hotels with nite numbers of rooms). The new hotel also tries to cater for superstitious guests. The most common superstition in Ves Lagos is that the number 13 brings bad luck. Accordingly, only numbers whose decimal forms do not contain the substring \13" will be used to label the rooms in the new hotel. For example, the hotel will have rooms numbered 1, 3, 14, 31, 123, but will not have the rooms 13, 132, 913, 1308, 1313. Let's consider the list of all room numbers, ordered increasingly. Find the N-th number in this list (members of the list are indexed from 1). Input The input le contains several test cases. The rst line of the le contains T (1 ≤ T ≤ 100), the number of test cases. Each of the following T lines describes one test case and contains the integer N (1 ≤ N ≤ 1018). Output The output le should contain exactly T lines, with the i-th line containing exactly one integer, the answer for the i-th test case from the input le.
Example hotel.in hotel.out
3
20
150
1
21
162
1
//题意,原来 1-n 标号的房间,现在,不想出现数字中有13 数字,问,原来的第 n 个们应标号为多少?
题解:由于数据特别大,所以要数位DP,套好模板后,还需要二分搜索标号为多少,注意的是,要尽量小,不然有一些重叠的
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define LL unsigned long long
#define MX 100005 LL n;
LL dp[][]; void Init()
{
dp[][]=;
for (int i=;i<=;i++)
{
dp[i][]=dp[i-][]*+dp[i-][];
dp[i][]=dp[i-][];
dp[i][]=dp[i-][]*-dp[i-][];
}
} LL slove(LL x)
{
LL a[],len=;
while (x)
{
a[++len]=x%;
x/=;
}
a[len+]=; LL ans =;
int flag=;
for (int i=len;i>;i--)
{
ans+=dp[i-][]*a[i];
if (flag)
ans+=dp[i-][]*a[i];
if (!flag&&((a[i]==&&a[i-]>)||(a[i]>)))
ans+=dp[i-][];
if (a[i]==&&a[i+]==)
flag=;
}
return ans;
} int main()
{
freopen("hotel.in","r",stdin);
freopen("hotel.out","w",stdout);
Init();
int t;
cin>>t;
while (t--)
{
cin>>n;
LL l=,r=1e19;
LL ans;
while (l<=r)
{
LL mid = (l+r)>>;
LL tp = mid-slove(mid+);
if (tp>=n)
{
ans = mid;
r=mid-;
}
else if (tp<n)
l=mid+;
}
cout<<ans<<endl;
}
return ;
}
Problem H. Hotel in Ves Lagos的更多相关文章
- 【数位dp】【二分】Gym - 101411H - Hotel in Ves Lagos
数位dp预处理之后,可以容易得到f(x),代表小于等于x的数中,有多少个不含13的.然后就能二分答案啦. #include<cstdio> #include<iostream> ...
- 实验12:Problem H: 整型数组运算符重载
Home Web Board ProblemSet Standing Status Statistics Problem H: 整型数组运算符重载 Problem H: 整型数组运算符重载 Tim ...
- The Ninth Hunan Collegiate Programming Contest (2013) Problem H
Problem H High bridge, low bridge Q: There are one high bridge and one low bridge across the river. ...
- Gym 100531H Problem H. Hiking in the Hills 二分
Problem H. Hiking in the Hills 题目连接: http://codeforces.com/gym/100531/attachments Description Helen ...
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
- Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉
Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- 清北学堂入学测试P4751 H’s problem(h)
P4751 H’s problem(h) 时间: 1000ms / 空间: 655360KiB / Java类名: Main 背景 冬令营入学测试 描述 小H是一个喜欢逛街的女孩子,但是由于上了大学 ...
- Problem H
Problem Description 穿过幽谷意味着离大魔王lemon已经无限接近了! 可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫的考验,这是魔王lemon设下的又一个 ...
- 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem H. Password Service dp
Problem H. Password Service 题目连接: http://www.codeforces.com/gym/100253 Description Startups are here ...
随机推荐
- vue scoped 解决样式不生效问题
对于添加样式不能影响子组件样式的情况使用:>>> <style scoped> .sti-inline{ display: inline; } .sti-searchfo ...
- PgSql备份pg_dump与还原手记pg_restore(转)可以直接跳转至最后面的示例进行查看
PgSql备份pg_dump与还原手记pg_restore(转) 可以直接跳转至最后面的示例进行查看 真没有想到,以前一直是PostgreSQL使用者,突然需要库移植又成了头一招了!原来它与mysql ...
- linux之getopt 函数(转)
命令行参数解析函数 —— getopt() getopt()函数声明如下: #include <unistd.h> int getopt(int argc, char * const ar ...
- loadrunner两个函数:取参数长度和时间戳函数
出自中国IT实验室2014-05-23 00:01 1.web_save_param_length 函数 函数原型:int web_save_param_length( const char *Par ...
- Android ListView工作原理全然解析,带你从源代码的角度彻底理解
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/44996879 在Android全部经常使用的原生控件其中.使用方法最复杂的应该就是 ...
- 通过Jenkins部署java项目
部署java项目-创建私有仓库 Jenkins大多数情况下都是用来部署Java项目,Java项目有一个特点是需要编译和打包的,一般情况下编译和打包都是用maven完成,所以系统环境中需要安装maven ...
- iBatis in或not in 查询
iBatis in或not in 查询 open:内容开头 close:内容结尾 conjunction:分隔符 <isNotNull prepend="and" pro ...
- 电脑 F键(功能键)的具体作用
F1:如果你处在一个选定的程序中而需要帮助,那么请按下F1.如果现在不是处在任何程序中,而是处在资源管理器或桌面,那么按下F1就会出现Windows的帮助程序.如果你正在对某个程序进行操作,而想得到W ...
- JQuery选择器大全 前端面试送命题:面试题篇 对IOC和DI的通俗理解 c#中关于协变性和逆变性(又叫抗变)帮助理解
JQuery选择器大全 jQuery 的选择器可谓之强大无比,这里简单地总结一下常用的元素查找方法 $("#myELement") 选择id值等于myElement的元素 ...
- MVC之ActionFilterAttribute自定义属性
ActionFilterAttribute里有OnActionExecuting方法,跟Controller一样, 同是抽象实现了IActionFilter接口. // 登录认证特性 public c ...