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 ...
随机推荐
- python判断文件和文件夹是否存在、创建文件夹
>>> import os >>> os.path.exists('d:/assist') True >>> os.path.exists('d: ...
- 程序员的笔记工具——Markdown
安利一款轻量级的标记语言——Markdown 如上,Markdown作为一门语言,十分钟即可入门,熟练以后麻麻再也不用担心我在文章排版上浪费时间了!! 入门资源可参考如下回答(建议拣一条完整的看完上手 ...
- nvidia显卡驱动卸载和卸载后的问题
因为装了nvidia显卡驱动后开机一直处于循环登录界面.password输入正确也是进不去.然后就决定卸载nvidia显卡驱动.安装之后出现还是循环登陆. 是openGL的问题 有至少两种解决方 ...
- mysql分组取最大(最小、最新、前N条)条记录
在数据库开发过程中,我们要为每种类型的数据取出前几条记录,或者是取最新.最小.最大等等,这个该如何实现呢,本文章向大家介绍如何实现mysql分组取最大(最小.最新.前N条)条记录.需要的可以参考一下. ...
- unity, 自定义类中使用print
在unity脚本中自定义c#类,而且不继承MonoBehaviour的话,若还想在其中使用print函数,可以用MonoBehaviour.print(...).
- angular4 radio checkbox 有用
<span *ngFor="let op of [{'id':'a','text':'11'},{'id':'b','text':'2222'},{'id':'cc','text':' ...
- Knockout JS 演示样例
五个小样例,来自Knockout JS官方站点. //tutorial 1 //following codes uses to demonstrate observable values and ta ...
- UITabelViewFootView(转)
在处理UITableView表格时,我们希望在View底部添加按钮. 用户拖动UITableView时按钮能跟随移动. 如题,实现如下界面: - (CGFloat)tableView:(UITable ...
- Android Studio 使用笔记:[转] Mac下修改Android Studio 所用的JDK版本
原文链接:http://www.jianshu.com/p/d8d1d72d0248# 最近项目从Eclipse+Ant构建模式转移到了Android Studio+Gradle构建模式,自然的JDK ...
- sqrt函数实现(神奇的算法)
我们平时经常会有一些数据运算的操作,需要调用sqrt,exp,abs等函数,那么时候你有没有想过:这个些函数系统是如何实现的?就拿最常用的sqrt函数来说吧,系统怎么来实现这个经常调用的函数呢? 虽然 ...