TOJ 4483: Common Digit Pairs
来源:互联网 发布:游戏王gx结局知乎 编辑:程序博客网 时间:2024/05/21 12:30
4483: Common Digit Pairs
Description
Given N integers, output the number of different pairs that two numbers have common digits. For example, given 3 integers: 1 11 21, there are 3 common digit pairs: <1, 11>, <1, 21>, <11, 21>.
Input
The first line has a positive integer N (1 ≤ N ≤ 1,000,000), then follow N different positive integers in the next N lines, each integer is no more than 1018.
Output
Output the numbers of different common digit pairs.
Sample Input
3
1
11
21
Sample Output
3
刚看是没有思路的,因为他讲数字对不是很明白,倘若是每位一定要超时的,毕竟有那个多个数,也想到了hash,但是发现复杂程度并没有有效得到减小,所以二进位hash就显示出他的力量的了,分别用2的n次幂去存一下每一个数拥有的数字,然后又一步很重要,就是异或,异或有相同位就成立,所以这样处理还是蛮厉害的。因为最多2的9次,相加为2的10次-1,所以数组1024足够
#include <stdio.h>__int64 s[1024];int a[10]; int main(){int n;a[0]=1;for(int i=1;i<10;i++)a[i]=a[i-1]*2;scanf("%d",&n);getchar();while(n--){char c;bool b[10]={0};while(c=getchar(),c!='\n'){b[c-48]=1;}int e=0;for(int k=0;k<10;k++)if(b[k]) e+=a[k];s[e]++;}__int64 f=0;for(int i=1;i<1024;i++){ f+=s[i]*(s[i]-1)/2; for(int j=1;j<i;j++) if(i&j) f+=s[i]*s[j];}printf("%I64d",f); return 0;}
0 0
- TOJ 4483: Common Digit Pairs
- toj 2857. Digit Sorting
- TOJ:Least Common Multiple
- toj 1528 Least Common Multiple
- projecteuler No.90 Cube digit pairs
- Project Euler:Problem 90 Cube digit pairs
- TOJ 10007 The last non-zero digit of n!
- TOJ 1683 Common Subsequence 最长公共子序列 依然DP
- pairs
- pairs
- TOJ 3033 ZOJ 1141 POJ 1470 Closest Common Ancestors / 最近公共祖先
- TOJ 2976
- toj 3140
- toj 1153
- TOJ 1772
- TOJ 3250
- TOJ 3051
- TOJ 4303
- 关于vs2015每次打开都要配置opencv问题
- CCF 学生排队 Java实现
- struts2 基本配置和介绍
- 翻转链表
- 文章标题
- TOJ 4483: Common Digit Pairs
- 学习淘淘商城第十六课(展示后台管理页面)
- 初识嵌入式
- Java中垃圾回收机制
- NBUT1223-Friends number
- Mac上安装MyEclipse2015 Mac破解版下载
- 朝鲜战争中的牺牲者
- rabbitMq使用笔记一:Window下安装使用RabbitMQ
- zstu4274-约素