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. HDU 2546 饭卡(带限制的01背包变形)

    思路:有几个解法,如下 1)先拿出5块买最贵的菜,剩下的菜再进行01背包.如何证明正确性?设最贵的菜价e,次贵的菜价s,设减去5后的余额为x,会不会产生这样的情况,假设用5元买了e,余额最多能买到x- ...

  2. BZOJ 2851: 极限满月 虚树 or 树链的并

    2851: 极限满月 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 170  Solved: 82[Submit][Status][Discuss] ...

  3. python基础教程总结15——6 CGI远程编辑

    功能: 将文档作为普通网页显示: 在web表单的文本域内显示文档: 保存表单中的文本: 使用密码保护文档: 容易拓展,支持处理多余一个文档的情况 1.CGI CGI(Comment Gateway I ...

  4. 广播监听USB插入与拔出

    package com.joy.usbbroadcastreceiver; import android.content.BroadcastReceiver; import android.conte ...

  5. Problem N: 求二维数组中的鞍点【数组】

    Problem N: 求二维数组中的鞍点[数组] Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 2764  Solved: 1728[Submit][S ...

  6. solver

    slover中有type,用于优化算法的选择,有6种: Stochastic Gradient Descent (type: “SGD”), AdaDelta (type: “AdaDelta”), ...

  7. 最大长度回文子串(Manacher's algorithm)

    输出最大长度的回文子串. string longestPalindrome(string s) { int id, mx, i, j, len, maxlen; vector<char> ...

  8. MFC中获得各种指针概述(个人觉得是很重要的重点)

    前言:这学期学习MFC(有点过时的东西),上课时,老师讲到获取当前活动指针,获取视图指针,文档指针,文档模板指针等(已晕) 后来下来真正写代码的时候发现这些几乎都是需要用到的东西,所以特此记录下,让自 ...

  9. jquery源码学习第一天

    第一天认识了jquery的大体结构,总的大范围是 (function() { // 这里是封装的代码,包括了各种方法.工具 window.JQuery = JQuery window.$ = $; } ...

  10. cesium 基于天地图服务 完成底图标注渲染加切换

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...