【Codeforces 1036C】Classy Numbers
【链接】 我是链接,点我呀:)
【题意】
让你求出只由3个非0数字组成的数字在[li,ri]这个区间里面有多少个.
【题解】
只由3个非0数字组成的数字在1~10^18中只有60W个
dfs处理出来之后排序做个二分查找一下区间里有多少个就好。
【代码】
import java.io.*;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static int N = 700000;
static class Task{
TreeSet<Long> myset = new TreeSet<Long>();
long a[] = new long[N+10];
int T,n;
long l,r;
void dfs(long cur,int num,int dep) {
if (dep==18) {
if (cur>0) myset.add(cur);
return;
}
if (num<3) {
for (int j = 1;j <= 9;j++)
dfs(cur*10+j,num+1,dep+1);
}
dfs(cur*10,num,dep+1);
}
int get_least_gore(long x) {
int l = 1,r = n,temp = 1;
while (l<=r) {
int mid = (l+r)/2;
if (a[mid]>=x) {
temp = mid;
r = mid - 1;
}else l = mid + 1;
}
return temp;
}
int get_last_lore(long x) {
int l = 1,r = n,temp = 1;
while (l<=r) {
int mid = (l+r)/2;
if (a[mid]<=x) {
temp = mid;
l = mid + 1;
}else r = mid - 1;
}
return temp;
}
public void solve(InputReader in,PrintWriter out) {
myset.add((long)1e18);
dfs(0,0,0);
n = myset.size();
Iterator<Long> it = myset.iterator();
int j = 1;
while (it.hasNext()) {
a[j] = it.next();
j++;
}
T = in.nextInt();
for (int ii = 1;ii <= T;ii++) {
l = in.nextLong();r = in.nextLong();
int idx1 = get_least_gore(l);
int idx2 = get_last_lore(r);
out.println(idx2-idx1+1);
}
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
【Codeforces 1036C】Classy Numbers的更多相关文章
- 【Codeforces 300C】Beautiful Numbers
[链接] 我是链接,点我呀:) [题意] 让你找到长度为n的数字 这个数字只由a或者b组成 且这n个数码的和也是由a或者b组成的 求出满足这样要求的数字的个数 [题解] 枚举答案数字中b的个数为y,那 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【66.47%】【codeforces 556B】Case of Fake Numbers
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 746E】Numbers Exchange
[题目链接]:http://codeforces.com/problemset/problem/746/E [题意] 你有n张卡片,上面写着不同的数字; 然后另外一个人有m张上面写着不同的数字的卡片: ...
- 【codeforces 367C】Sereja and the Arrangement of Numbers
[题目链接]:http://codeforces.com/problemset/problem/367/C [题意] 我们称一个数列a[N]美丽; 当且仅当,数列中出现的每一对数字都有相邻的. 给你n ...
- 【19.77%】【codeforces 570D】Tree Requests
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【35.37%】【codeforces 556C】Case of Matryoshkas
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【34.57%】【codeforces 557D】Vitaly and Cycle
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【55.70%】【codeforces 557A】Ilya and Diplomas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
随机推荐
- 【149】ArcGIS Desktop 10.0 & Engine 10.0 安装及破解
写在前面:可能会出现按照此方法无法破解的情况,那请确保您有将 ArcGIS 10.0 已经完全卸载干净,直接通过控制面板进行卸载的时候并不能将其卸载干净,需要进行更深层次的卸载,包括删除注册表,各种文 ...
- Unity资源的查找
Object.Destroy static function Destroy(obj: Object, t: float = 0.0F): void; Description Removes a ...
- wamp集成环境下帝国备份出错
我在本地wamp环境下面使用帝国备份王时,报错信息如下: Parse error: syntaxerror, unexpected $end in D:wampwwwhuifuclassfunctio ...
- [App Store Connect帮助]六、测试 Beta 版本(1)TestFlight Beta 版测试概述(iOS、Apple TVOS、watchOS)
TestFlight Beta 版测试让您可以分发您 App 的 Beta 版构建版本给测试员并收集反馈.您可以在您的 App Store Connect 帐户中一次为至多 100 个 App 启用 ...
- 慕课网2-5 编程练习:通过jQuery通配符选择器进行文字变色
2-5 编程练习 请请使用*选择器将div标签中的字体颜色变成红色 效果图: 任务 (1)使用通配符选择器 (2)使用jQuery的.css()方法设置样式,语法css('属性 '属性值') 参考代码 ...
- Hadoop伪分布式模式搭建
title: Hadoop伪分布式模式搭建 Quitters never win and winners never quit. 运行环境: Ubuntu18.10-server版镜像:ubuntu- ...
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Overlapping Rectangles
There are nn rectangles on the plane. The problem is to find the area of the union of these rectangl ...
- RHEL5.6环境下yum安装MySQL
RHEL5.6环境下yum安装MySQL记录,2017年2月20日 1.卸载原有的MySQL rpm -qa命令查询是否安装了MySQL [root@localhost mysql]# rpm -qa ...
- Oracle 参考脚本
一.创建物化视图 --新建表空间 CREATE TABLESPACE MLOG_TBS LOGGING DATAFILE 'mlog_tbs.dbf' SIZE 32M AUTOEXTEND ON N ...
- EasyUI系列学习(五)-Resizable(调整大小)
一.创建组件 1.使用标签创建可变大小的窗口 <div id="rBox" class="easyui-resizable" style="wi ...