4483: Common Digit Pairs 

Time Limit(Common/Java):3000MS/9000MS     Memory Limit:65536KByte
Total Submit: 90            Accepted:14

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

有相同字符就视为一对,问你有多少对,以下为n^2的超时代码

#include <stdio.h>
char s[][];
int main()
{int n;
scanf("%d",&n);
getchar();
for(int i=;i<n;i++)
scanf("%s",s[i]);
int e=,f;
for(int i=;i<n;i++)
for(int j=i+;j<n;j++){
f=;
for(int k=;s[i][k];k++){
for(int l=;s[j][l];l++)
if(s[i][k]==s[j][l]){
e++;f=;
break;
}
if(f)break;}
}
printf("%d",e);
return ;
}

位运算状态压缩就可以了的很短时间的代码

#include <stdio.h>
__int64 s[];
int a[];
int main()
{
int n;
a[]=;
for(int i=; i<; i++)
a[i]=a[i-]*;
scanf("%d",&n);
getchar();
while(n--)
{
char c;
bool b[]= {};
while(c=getchar(),c!='\n')
{
b[c-]=;
}
int e=;
for(int k=; k<; k++)
if(b[k])
e+=a[k];
s[e]++;
}
__int64 f=;
for(int i=; i<; i++)
{
f+=s[i]*(s[i]-)/;
for(int j=; j<i; j++)
if(i&j)
f+=s[i]*s[j];
}
printf("%I64d",f);
return ;
}

最新文章

  1. JS中常遇到的浏览器兼容问题和解决方法
  2. AgileEAS.NET SOA 中间件平台.Net Socket通信框架-完整应用例子-在线聊天室系统-下载配置
  3. wdcp 下apache模式开启https访问,支持多站点
  4. css 字间距、CSS字体间距、css 字符间距设置
  5. SharePoint 2013中的默认爬网文件扩展名和分析文件类型
  6. Bootstrap页面布局18 - BS导航路径以及分页器
  7. Js笔试题之千分位格式化
  8. Stunnix C++ Obfuscator使用简介
  9. .net performance
  10. EDStarRating(IOS星级评定)
  11. 条件变量signal与unlock的顺序
  12. php索引数组转成关联数组
  13. Servlet 笔记-过滤器
  14. Linux安装JDK步骤
  15. 老司机教你在windows不用软件隐藏重要文件
  16. 44.Linux君正X1000-添加st7789v显示
  17. jQuery的节点添加、删除、替换等操作
  18. 100以内与7有关的数(for和if)
  19. epoll, NIO,AIO
  20. 使用openssh-clients的scp命令来传输文件

热门文章

  1. python 之正则表达式
  2. CSS中padding、margin两个重要属性的详细介绍及举例说明
  3. 【Python图像特征的音乐序列生成】GitHub已经有人将mingus改到了Python3版本
  4. 使Win10用户获得特殊权限以便删除相应文件(夹)
  5. 日常-acm-三位数反转
  6. 2018.4.15 Mac系统下如何使用StartUml画好需求分析的类图 (同样适用于windows)
  7. 原型模式 -- JavaScript语言的灵魂
  8. Xcode中的Project和Target
  9. d3.js--03(增删改查)
  10. Angular - Can&#39;t bind to &#39;ngModel&#39; since it isn&#39;t a known property of &#39;input&#39;.