题目描述

某人刚学习了数位DP,他在某天忽然思考如下问题:

给定n,问有多少数对<x, y>满足:

x, y∈[1, n], x < y

x, y中出现的[0, 9]的数码种类相同

输入

一个整数n (n <= 107)

输出

输出一个数即答案

样例输入

30

样例输出

3

提示

<1, 11> <2, 22> <12, 21>

来源

郑州轻工业学院第十届ACM程序设计大赛

这题是思路是x,y在1~n内,而且x和y中出现的数码相同,因此,我们可以暴力存从1到n的所有数码状态的个数。 然后求个组合就行了。

比如:12 121 121212 1212121 212121 这几个数的数码都是12,那么数码为12的个数为5,这五个数任取两个都可以组成一种x,y。

具体看代码:

 1 #include<iostream>
2 #include <cstdio>
3 #include <cmath>
4 #include <cstring>
5 #include <algorithm>
6 #include <string>
7 typedef long long ll;
8 using namespace std;
9 const int maxn = 1e6;
10 const int inf = 0x3f3f3f3f;
11 int nu[maxn];
12 int dis[maxn];
13 int vis[11];
14 using namespace std;
15 int main()
16 {
17 int n;
18 scanf("%d", &n);
19 for(int i = 1; i <= n; ++i) {
20 memset(vis, 0 , sizeof(vis));
21 int x = i;
22 while(x) {
23 vis[x % 10] = 1;
24 x /= 10;
25 }
26 int num = 0;
27 for(int j = 0; j <= 9; ++j) {
28 if(vis[j]) {
29 num += 1 << j;
30 }
31 }
32 nu[num]++;
33 }
34 ll ans = 0;
35 for(int i = 0; i < (1 << 10); ++i) {
36 if(nu[i])
37 ans += nu[i] * (nu[i] - 1) / 2;
38 }
39 printf("%lld\n", ans);
40 return 0;
41 }

zzuli-2266 number的更多相关文章

  1. 轻院校赛-zzuli 2266: number【用每位的二进制的幂的和来进行hash(映射)处理】

    zzuli 2266: number 大致题意:   给定n,问有多少数对<x, y>满足: x, y∈[1, n], x < y            x, y中出现的[0, 9] ...

  2. zzuli 1817: match number 模拟

    1817: match number Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 199  Solved: 72 SubmitStatusWeb B ...

  3. JavaScript Math和Number对象

    目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...

  4. Harmonic Number(调和级数+欧拉常数)

    题意:求f(n)=1/1+1/2+1/3+1/4-1/n   (1 ≤ n ≤ 108).,精确到10-8    (原题在文末) 知识点:      调和级数(即f(n))至今没有一个完全正确的公式, ...

  5. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  6. Eclipse "Unable to install breakpoint due to missing line number attributes..."

    Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...

  7. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  8. iOS---The maximum number of apps for free development profiles has been reached.

    真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...

  9. 有理数的稠密性(The rational points are dense on the number axis.)

    每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.

  10. [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

随机推荐

  1. linux7下修改主机名的方式

    在基于linux发行版的众多linux kernel 3.0以上,包括rhel7,centos7等提供多种修改linux主机名的方式 1.通过编辑/etc/hostname文件 2.命令hostnam ...

  2. 7行代码解决P1441砝码称重(附优化过程)

    先贴上最终代码感受一下: #include <bits/stdc++.h> using namespace std; int i, N, M, wi[21], res = 0; int m ...

  3. CNN可视化技术总结(一)--特征图可视化

    导言: 在CV很多方向所谓改进模型,改进网络,都是在按照人的主观思想在改进,常常在说CNN的本质是提取特征,但并不知道它提取了什么特征,哪些区域对于识别真正起作用,也不知道网络是根据什么得出了分类结果 ...

  4. 详解Mybatis拦截器(从使用到源码)

    详解Mybatis拦截器(从使用到源码) MyBatis提供了一种插件(plugin)的功能,虽然叫做插件,但其实这是拦截器功能. 本文从配置到源码进行分析. 一.拦截器介绍 MyBatis 允许你在 ...

  5. 第一个 IDEA 应用程序

    新建 Java Web 项目 打开 IDEA -> Create New Project 选择 Java -> Java EE -> Web Application 选择工作空间 项 ...

  6. Python学习【第8篇】:python中的函数

    1.python中函数定义方法 def test(x): "This istest" y = x*2+1 return y vaule = test(2)print(vaule)运 ...

  7. Flash图解线程池 | 阿里巴巴面试官希望问的线程池到底是什么?

    前言 前几天小强去阿里巴巴面试Java岗,止步于二面. 他和我诉苦自己被虐的多惨多惨,特别是深挖线程和线程池的时候,居然被问到不知道如何作答. 对于他的遭遇,结合他过了一面的那个嘚瑟样,我深表同情(加 ...

  8. js基础(使用Canvas画图)

    HTML5的元素提供了一组JavaScript API,让我们可以动态地创建图形和图像. 图形是在一个特定的上下文中创建的,而上下文对象目前有两种.第一种是2D上下文,可以执行原始的绘图操作, 比如: ...

  9. Java线程 - sleep()和wait()方法的区别, 线程阻塞BLOCKED和等待WAITING的区别

    一. sleep()和wait()方法的区别 sleep()方法 sleep()方法是Thread类的方法,通过其定义可知是个native方法,在指定的时间内阻塞线程的执行.而且从其注释中可知,并不会 ...

  10. 2019 ccpc秦皇岛

    1006 (dfs) #include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const dou ...