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 ...
随机推荐
- 微信团队原创分享:iOS版微信的内存监控系统技术实践
本文来自微信开发团队yangyang的技术分享. 一.前言 FOOM(Foreground Out Of Memory),是指App在前台因消耗内存过多引起系统强杀.对用户而言,表现跟crash一样. ...
- 8_陀螺仪MPU6050和PWM控制在STM32F4-Discovery开发板上的实现
非常早曾经就把圆点博士的程序从STM32F103移植到STM32F4_Discovery (STM32F407), battery.陀螺仪和PWM电机控制的程序都已经測试完成,执行有一段时间,正常.以 ...
- 《深入理解jvm》笔记---第七章
虚拟机类载入机制 1. 类的生命周期: 载入.验证.准备.解析.初始化.使用.卸载七个阶段.当中验证.准备.解析三个阶段统称为连接. 当中,解析的阶段的时机并不一定. 2. Java类载入的时机: J ...
- ViewPager中Fragment无法显示的问题
问题描述: Actvitiy->Fragment1 ->Fragment2 Fragment1中有1个ViewPager,ViewPager里面有包括了2个Fragment. 当第一次执行 ...
- MongoDB笔记(二):MongoDB下Shell的基本操作
一.mongoDB与关系型数据库对比 对比项 mongoDB 关系型数据库(oracle.mysql) 表 集合List 二维表table 表的一行数 ...
- html标签说明
dictype 不区分大小写 HTML 4.01 与 HTML5 之间的差异 在 HTML 4.01 中有三种 <!DOCTYPE> 声明.在 HTML5 中只有一种: <!DOCT ...
- 牛散NO.1:MACD计啜诱多,勾魂枪连环夺命时
上证日线“连环夺命勾魂枪” 话说MACD中圈C的回勾,好事者皆认为新的冲击波即将曙光再现.伴随着K线出现红柱中阳,更多的投资者将会被这一勾诱惑得群情亢奋,盲断行情又要 起来了.但往往事与愿违,“潘金莲 ...
- CF 316div2 E.Pig and Palindromes
E. Pig and Palindromes Peppa the Pig was walking and walked into the forest. What a strange coincide ...
- vue 跨域:使用vue-cli 配置 proxyTable 实现跨域问题
路径在/config/index.js 中,找到dev.proxyTable.如下配置示例: proxyTable: { '/api': { // 我要请求的地址 target: 'http://oa ...
- Atitit.通过null 参数 反射 动态反推方法调用
Atitit.通过null 参数 反射 动态反推方法调用 此时,直接使用java apache的ref工具都失效了.必须要自己实现了. 如果调用接口方法的话,就不能使用apache的ref工具,可 ...