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 ...
随机推荐
- HDU 5500 Reorder the Books (水题)
题意: 有n本书,编号为1~n,现在书的顺序乱了,要求恢复成有序的样子,每次只能抽出其中一本并插到最前面,问最少需要多少抽几次? 思路: 如果pos[i]放的不是书i的话,则书i的右边所有的书都必须抽 ...
- python基础教程总结9——模块,包,标准库
1. 模块 在python中一个文件可以被看成一个独立模块,而包对应着文件夹,模块把python代码分成一些有组织的代码段,通过导入的方式实现代码重用. 1.1 模块搜索路径 导入模块时,是按照sys ...
- 如何处理VirtualBox启动错误消息:The vboxdrv kernel module is not loaded
我在启动minikube时,遇到如下错误消息: Starting local Kubernetes v1.10.0 cluster... Starting VM... E1010 03:27:37.9 ...
- input输入大于0的小数和整数
<input onkeyup="num(this)"onbeforepaste="num(this)"> <script src='jquer ...
- ubuntu 使用apt命令时报错 E: Could not get lock /var/lib/dpkg/lock - open...
问题描述: 刚刚安装好Ubuntu16.04.使用apt命令时,提示报错信息: abc@pc:~$ sudo apt-get install openssh-server E: Could not g ...
- pycharm创建工程的两种形式:virtualenv环境和系统默认编译器
转自:http://swiftlet.net/archives/3151 pycharm创建工程的时候可以选择编译器,如下图所示: 上图表示创建工程有两种方式:第一种是利用:virtualenv,第二 ...
- C++内联函数、宏定义和普通函数的区别
C++内联函数.宏定义和普通函数的区别? 宏定义:在预处理阶段进行简单的文本替换,不会进行参数类型检查: 内联函数:在编译器的时候进行代码插入,编译器会在每次调用内联函数的地方直接将内联函数的内容展开 ...
- Vue和MVVM对应关系
Vue和MVVM的对应关系 Vue是受MVVM启发的,那么有哪些相同之处呢?以及对应关系? MVVM(Model-view-viewmodel) MVVM还有一种模式model-view-binder ...
- jq 下拉框
<div class="alls"> <div class="item"> <div class="all"& ...
- CNCF 有哪些具体的项目内容?
前言:CNCF(Cloud Native Computing Foundation)于 2015 年 7 月成立,隶属于 Linux 基金会,初衷围绕“云原生”服务云计算,致力于维护和集成开源技术,支 ...