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. 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何把FBD功能块转换成ST语言

    假如我定义了一个MC_Power的标准功能块,我想知道它对应的ST语言   在MAIN(ST语言界面下)右击,Input Assistant,然后找到Standard Function Blocks, ...

  2. HTML 中图片的隐藏与显示

    <html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Co ...

  3. Centos系统信息及日志

    1.确认内核版本: #uname -r #uname -a 2.确认发行版本: #cat /etc/redhat-release 3.查看系统载入的模块: #lsmod | grep XXX 载入一个 ...

  4. web 前端 常见操作 将时间戳转成日期格式 字符串截取 使用mui制作选项卡

    1.将时间戳转成日期格式: //第一种 function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString( ...

  5. 20180113Go匿名函数和闭包

    最近codereview看到闭包,得学习下 https://studygolang.com/articles/5057 匿名函数:没有函数名的函数 闭包:外部函数定义的内部函数. 闭包给访问外部函数定 ...

  6. 服务器上使用matplotlib.pyplot绘图

    在linux服务器端执行python脚本,有时候需要画图,但是linux没有GUI界面,因此需要在导入matplotlib.pyplot库之前先执行 import matplotlib as mpl ...

  7. java中的参数传递——值传递、引用传递

    参数是按值而不是按引用传递的说明 Java 应用程序有且仅有的一种参数传递机制,即按值传递. 在 Java 应用程序中永远不会传递对象,而只传递对象引用.因此是按引用传递对象.Java 应用程序按引用 ...

  8. script

    实例 链接一个外部脚本文件: <script type="text/javascript" src="myscripts.js"></scri ...

  9. C++语言基础(10)-虚继承

    一.产生背景 先看下列一份代码: //间接基类A class A{ protected: int m_a; }; //直接基类B class B: public A{ protected: int m ...

  10. RunTime.getRunTime().addShutdownHook用法

    今天在阅读Tomcat源码的时候,catalina这个类中使用了下边的代码,不是很了解,所以google了一下,然后测试下方法,Tomcat中的相关代码如下: Runtime.getRuntime() ...