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的更多相关文章

  1. 【数位dp】【二分】Gym - 101411H - Hotel in Ves Lagos

    数位dp预处理之后,可以容易得到f(x),代表小于等于x的数中,有多少个不含13的.然后就能二分答案啦. #include<cstdio> #include<iostream> ...

  2. 实验12:Problem H: 整型数组运算符重载

    Home Web Board ProblemSet Standing Status Statistics   Problem H: 整型数组运算符重载 Problem H: 整型数组运算符重载 Tim ...

  3. 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. ...

  4. Gym 100531H Problem H. Hiking in the Hills 二分

    Problem H. Hiking in the Hills 题目连接: http://codeforces.com/gym/100531/attachments Description Helen ...

  5. Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

    Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...

  6. Codeforces Gym 100342H Problem H. Hard Test 构造题,卡迪杰斯特拉

    Problem H. Hard TestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  7. 清北学堂入学测试P4751 H’s problem(h)

    P4751 H’s problem(h)  时间: 1000ms / 空间: 655360KiB / Java类名: Main 背景 冬令营入学测试 描述 小H是一个喜欢逛街的女孩子,但是由于上了大学 ...

  8. Problem H

    Problem Description 穿过幽谷意味着离大魔王lemon已经无限接近了! 可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫的考验,这是魔王lemon设下的又一个 ...

  9. 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 ...

随机推荐

  1. 手机号码月消费档次API

    手机号码月消费档次API,返回手机号的每月消费水平,身份证姓名不做一致性校验 文档:https://www.juhe.cn/docs/api/id/261 接口地址:http://v.juhe.cn/ ...

  2. RAID详解[RAID0/RAID1/RAID10/RAID5] (转)

    一.RAID定义RAID(Redundant Array of Independent Disk 独立冗余磁盘阵列)技术是加州大学伯克利分校1987年提出,最初是为了组合小的廉价磁盘来代替大的昂贵磁盘 ...

  3. IFrame和Ajax比較

    说到比較,可能我是须要把这连个东西都给大家介绍一下的,可是介于大家都已经有了非常多的理解.我就简单的说了. Ajax:             是指一种创建交互式网页应用的网页开发技术.主要是利用Xm ...

  4. android adt 最新下载地址23.03

    打开这个网址就可以看到adt的详细信息:  http://developer.android.com/sdk/installing/installing-adt.html 或者直接在你的eclipse ...

  5. Windows网络配置脚本

    静态ip和动态ip切换 适用于:公司学校家庭的网络环境切换[请修改具体ip地址] ::ip for win7.bat::win8以上请用ipv4替换ip @echo off 设置为静态IP 设置为动态 ...

  6. jquery遍历DOM方法总结

    1.jQuery 遍历 - 祖先 向上遍历 DOM 树 这些 jQuery 方法很有用,它们用于向上遍历 DOM 树: parent() parents() parentsUntil() jQuery ...

  7. nginx跨域(转2)

    当出现403跨域错误的时候 No 'Access-Control-Allow-Origin' header is present on the requested resource,需要给Nginx服 ...

  8. JS防后退跳转

    location.replace("http://www.baidu.com");

  9. SourceTree代码管理学习git命令操作

    Git管理工具SourceTree提交代码时报文件名过长,用命令解决这个错误: 使用git status查看状态信息 git status 使用git add将修改后的文件(.代表全部文件)添加到暂存 ...

  10. Servlet3.0: 简介AsyncContext

    每个请求来到Web容器,Web容器会为其分配一条执行绪来专门负责该请求,直到回应完成前,该执行绪都不会被释放回容器. 执行绪会耗用系统资源,若有些请求需要长时间处理(例如长时间运算.等待某个资源),就 ...