题目描述

某人刚学习了数位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. 转 Jmeter测试实践:文件上传接口

    Jmeter测试实践:文件上传接口   1.打开jmeter4.0,新建测试计划,添加线程组.根据实际情况配置线程属性. 2.添加HTTP请求. Basic部分修改如下: Advanced部分我做任何 ...

  2. JavaScript常用API

    JavaScript常用API 节点属性 文档节点 事件监听.一出事件 获取元素方法

  3. 提取当前文件夹下的所有文件名.bat(Windows批处理文件)

    @echo off dir /s/b *.* > 文件名.txt exit

  4. 基于go-cqhttp实现QQ机器人

    本篇文章记录一下自己在编写QQ机器人的时候所遇到的一些问题和核心功能的实现. QQ机器人RabbitBot采用python编写,由于是个人学习使用,故目前不会开源完整代码,只会放出核心代码供学习参考. ...

  5. MySQL主从配置This operation cannot be performed with a running slave io thread; run STOP SLAVE IO_THREAD FOR CHANNEL '' first.

    MySQL主从配置This operation cannot be performed with a running slave io thread; run STOP SLAVE IO_THREAD ...

  6. Linux安装redis报错:jemalloc/jemalloc.h: No such file or directory踩坑

    报错内容: 针对这个错误,我们可以在README.md 文件中看到解释: --------- Selecting a non-default memory allocator when buildin ...

  7. 线上nginx的一次“no live upstreams while connecting to upstream ”分析

    线上nginx的一次"no live upstreams while connecting to upstream "分析 线上nginx的一次"no live upst ...

  8. CSRF Cross-site request forgery 跨站请求伪造

    跨站请求伪造目标站---无知用户---恶意站 http://fallensnow-jack.blogspot.com/2011/08/webgoat-csrf.html https://wiki.ca ...

  9. Phoenix简介概述,Phoenix的Java API 相关操作优秀案例

    Phoenix简介概述,Phoenix的Java API 相关操作优秀案例 一.Phoenix概述简介 二.Phoenix实例一:Java API操作 2.1 phoenix.properties 2 ...

  10. Centos7 yum 安装 oracle-rdbms-server-11gR2-pre

    Oracleyum官方网站 http://yum.oracle.com/ 一.下载yum源 根据自己需求下载相应的yum源 http://yum.oracle.com/getting-started. ...