TOJ4483: Common Digit Pairs
4483: Common Digit Pairs 
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的更多相关文章
- 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 ...
- 如何读懂 Intel HEX 文件
什么是 Intel HEX 文件格式 转自:http://www.cnblogs.com/imapla/archive/2013/03/16/2926133.htmlIntel HEX 文件是遵循 ...
- USACO Section 3.3 Camlot(BFS)
BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...
- USACO 3.3 Camelot
CamelotIOI 98 Centuries ago, King Arthur and the Knights of the Round Table used to meet every year ...
- hex文件和bin文件区别
HEX文件和BIN文件是我们经常碰到的2种文件格式.因为自己也是新手,所以一直对这两个文件懵懵懂懂,不甚了解,最近在做STM32单片机的IAP更新,其中要考虑HEX文件和BIN文件,所以需要学习下这两 ...
- webgoat 7.1 实战指南
WSASP中文文档参考链接: http://www.owasp.org.cn/owasp-project/2017-owasp-top-10 OWASP Top 10 2017中文版V1.3http: ...
- Common Knowledge_快速幂
问题 I: Common Knowledge 时间限制: 1 Sec 内存限制: 64 MB提交: 9 解决: 8[提交][状态][讨论版] 题目描述 Alice and Bob play som ...
- 【Codeforces715C&716E】Digit Tree 数学 + 点分治
C. Digit Tree time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ...
- Calculating Stereo Pairs
Calculating Stereo Pairs Written by Paul BourkeJuly 1999 Introduction The following discusses comput ...
随机推荐
- 不喜欢SAP GUI?那试试用Eclipse进行ABAP开发吧
Jerry和SAP成都研究院一些新同事聊天时,谈到ABAP和SAP GUI这个话题.很多新同事在加入SAP成都之前,是做Java和C++开发的,习惯了Eclipse/IntelliJ IDEA/Vis ...
- [dp][uestc oj]J - 男神的约会
J - 男神的约会 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...
- 使用Python-OpenCV向图片添加噪声(高斯噪声、椒盐噪声)
在matlab中,存在执行直接得函数来添加高斯噪声和椒盐噪声.Python-OpenCV中虽然不存在直接得函数,但是很容易使用相关的函数来实现. 代码: import numpy as np impo ...
- Python-OpenCV中的resize()函数
改变图像大小意味着改变尺寸,无论是单独的高或宽,还是两者.也可以按比例调整图像大小. 这里将介绍resize()函数的语法及实例. 语法 函数原型 cv2.resize(src, dsize[, ds ...
- DROP OPERATOR - 删除一个操作符
SYNOPSIS DROP OPERATOR name ( lefttype | NONE , righttype | NONE ) [ CASCADE | RESTRICT ] DESCRIPTIO ...
- JavaScript实用的例子
---恢复内容开始--- 1.发送验证码 <input id="send" type="button" value="发送验证码"&g ...
- 01_3_创建一个Servlet
01_3_创建一个Servlet 1.创建一个Servlet import java.io.IOException; import java.io.PrintWriter; import javax. ...
- iOS 骰子战争 Dice Wars
占坑 这个游戏之前在网页端玩过,App Store 上没有搜到特别好的,想自己做个类似的iOS APP 游戏 目测实现难度适中,可玩性较高
- cron job 里面,如何让脚本半分钟运行一次?
cron job 里面,如何让脚本半分钟运行一次? cron本身实现不了.但可以借助于sleep命令实现. 解决方法: 两个脚本 一个正常,一个增加sleep 30 crontab设置同时启动 在有的 ...
- c++ 定义一个结构体student,输入多个student的信息并以三种方式显示
#include <iostream> #include <string> using namespace std; const int slen = 30; struct s ...