zzuli-2266 number
题目描述
某人刚学习了数位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>
来源
这题是思路是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的更多相关文章
- 轻院校赛-zzuli 2266: number【用每位的二进制的幂的和来进行hash(映射)处理】
zzuli 2266: number 大致题意: 给定n,问有多少数对<x, y>满足: x, y∈[1, n], x < y x, y中出现的[0, 9] ...
- zzuli 1817: match number 模拟
1817: match number Time Limit: 1 Sec Memory Limit: 128 MB Submit: 199 Solved: 72 SubmitStatusWeb B ...
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- 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.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
随机推荐
- python多线程和GIL全局解释器锁
1.线程 线程被称为轻量级进程,是最小执行单元,系统调度的单位.线程切换需要的资源一般,效率一般. 2.多线程 在单个程序中同时运行多个线程完成不同的工作,称为多线程 3.并 ...
- shell批量解压源码包
有时候部署环境有很多安装包,如果一个一个地解压缩实在太麻烦了,可以用shell批量进行解压缩.命令如下: [root@localhost ~]# vi tar.sh #! /bin/bash #标称是 ...
- Connection Manager简称connman
ConnMan Connection Manager简称connman,connman是使用d-bus做为进程间通信机制来管理Linux网络链接的一种软件.在connman的d-bus接口中,有 ...
- VMwareWorkstation 平台 Ubuntu14 下安装配置 伪分布式 hadoop
VMwareWorkstation平台Ubuntu14下安装配置伪分布式hadoop 安装VmwareStation 内含注册机. 链接:https://pan.baidu.com/s/1j-vKgD ...
- Promise 中reject 和 catch 处理上有什么区别
reject 是用来抛出异常,catch 是用来处理异常reject 是 Promise 的方法,而 catch 是 Promise 实例的方法reject后的东西,一定会进入then中的第二个回调, ...
- promise有几种状态,什么时候会进入catch
三个状态:pending.fulfilled.reject两个过程:padding -> fulfilled.padding -> rejected当pending为rejectd时,会进 ...
- 阿里云服务器centos7,docker部署mysql+Redis+vue+springboot+Nginx+fastdfs,亲测可用
一.购买云服务器 我是今年双十一期间在阿里云购买的服务器, 简单配置2核_4G_40G_3M,三年用了不到800块,不过当时我记得腾讯云更便宜,个人感觉,阿里的云服务器更加的稳定, 毕竟身经百战, 经 ...
- Java面试,面试题
Java面试,面试题 HashMap,HashTable,ConcurrentHash的共同点和区别 HashMap HashTable ConcurrentHashMap ArrayList和Lin ...
- 函数式编程(json、pickle、shelve)
本节内容 前言 json模块 pickle模块 shelve模块 总结 一.前言 1. 现实需求 每种编程语言都有各自的数据类型,其中面向对象的编程语言还允许开发者自定义数据类型(如:自定义类),Py ...
- idea中将普通工程设置为maven项目
只需要在工程上右键,"Add Frameworks support...",然后选择Maven即可