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 ;
}

TOJ4483: Common Digit Pairs的更多相关文章

  1. Project Euler 90:Cube digit pairs 立方体数字对

    Cube digit pairs Each of the six faces on a cube has a different digit (0 to 9) written on it; the s ...

  2. 如何读懂 Intel HEX 文件

    什么是 Intel HEX 文件格式   转自:http://www.cnblogs.com/imapla/archive/2013/03/16/2926133.htmlIntel HEX 文件是遵循 ...

  3. USACO Section 3.3 Camlot(BFS)

    BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...

  4. USACO 3.3 Camelot

    CamelotIOI 98 Centuries ago, King Arthur and the Knights of the Round Table used to meet every year ...

  5. hex文件和bin文件区别

    HEX文件和BIN文件是我们经常碰到的2种文件格式.因为自己也是新手,所以一直对这两个文件懵懵懂懂,不甚了解,最近在做STM32单片机的IAP更新,其中要考虑HEX文件和BIN文件,所以需要学习下这两 ...

  6. webgoat 7.1 实战指南

    WSASP中文文档参考链接: http://www.owasp.org.cn/owasp-project/2017-owasp-top-10 OWASP Top 10 2017中文版V1.3http: ...

  7. Common Knowledge_快速幂

    问题 I: Common Knowledge 时间限制: 1 Sec  内存限制: 64 MB提交: 9  解决: 8[提交][状态][讨论版] 题目描述 Alice and Bob play som ...

  8. 【Codeforces715C&716E】Digit Tree 数学 + 点分治

    C. Digit Tree time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ...

  9. Calculating Stereo Pairs

    Calculating Stereo Pairs Written by Paul BourkeJuly 1999 Introduction The following discusses comput ...

随机推荐

  1. Linux环境下mysql的root密码忘记解决方法(2种)

    方法一: 1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以 ...

  2. Windows系统下查看文件编码类型

    这是一个程序员的最基本的技能,原谅我到现在才去了解 以前只知道window操作系统下文件大部分默认编码是ANSI,中文版是GBK编码 如果想要查看或者修改文件编码的话有两种方式 一:用记事本打开文件, ...

  3. div高度不能自适应(子级使用float浮动,父级div高度不能自适应)

    1.问题截图: 2.问题描述: 由于地址.公司名长度的不定性,所以每一条地址所在的父级div高度不定,但是需要设置一个最小的高度min-height:48px;但是当内容增加的时候,父级div高度却不 ...

  4. js进阶之闭包

    1.首先说下什么是闭包,闭:封闭,包:就像我们的包包~:虽然我在扯淡但是也有其道理咯,闭包就有点像java里面的封装一样,包属性和方法都封装到对象内部,在外部通过共有的get.set方法获取或者设置其 ...

  5. 2017年团体程序设计天梯赛 - 大区赛 L3-3

    题意:有向图找哈密顿回路 比赛的时候剪枝只剪了vis 状压没剪对 反而只拿17分... 比赛结束后还去看了一发这个NP问题的QB(快速回溯法...但是对于本题好像大材小用...) 上网看了一个神犇的写 ...

  6. JavaScript内存泄露,闭包内存泄露如何解决

    本文原链接:https://cloud.tencent.com/developer/article/1340979 JavaScript 内存泄露的4种方式及如何避免 简介 什么是内存泄露? Java ...

  7. 2017乌鲁木齐网络赛 j 题

    题目连接 : https://nanti.jisuanke.com/t/A1256 Life is a journey, and the road we travel has twists and t ...

  8. 使用Electron开发PC客户端

    最近公司要求开发一个PC客户端,要求不能使用.NET开发(为了不让用户安装.net framework),所以就选择了Electron(随口听别人说了一句,之前从来没有接触过).目前项目要完毕了,所以 ...

  9. AutoLayout处理UITableView动态高度

    我们经常会遇到UITableViewCell的高度要跟随内容而调整,在未引入AutoLayout之前,我们使用以下方法计算Label高度,然后heightForRowAtIndexPath中返回计算的 ...

  10. 51nod——1548 欧姆诺姆和糖果

    一开始以为是贪心,然后发现没法贪.暴力枚举肯定T,于是用约束关系优化: 假设wr >= wb, 第一种情况:wr >= sqrt (c), 则此时最多吃c / wr个r,且c / wr & ...