TOJ4483: Common Digit Pairs
2024-10-22 04:52:54
4483: Common Digit Pairs
Time Limit(Common/Java):3000MS/9000MS Memory Limit:65536KByte
Total Submit: 90 Accepted:14
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 ;
}
最新文章
- JS中常遇到的浏览器兼容问题和解决方法
- AgileEAS.NET SOA 中间件平台.Net Socket通信框架-完整应用例子-在线聊天室系统-下载配置
- wdcp 下apache模式开启https访问,支持多站点
- css 字间距、CSS字体间距、css 字符间距设置
- SharePoint 2013中的默认爬网文件扩展名和分析文件类型
- Bootstrap页面布局18 - BS导航路径以及分页器
- Js笔试题之千分位格式化
- Stunnix C++ Obfuscator使用简介
- .net performance
- EDStarRating(IOS星级评定)
- 条件变量signal与unlock的顺序
- php索引数组转成关联数组
- Servlet 笔记-过滤器
- Linux安装JDK步骤
- 老司机教你在windows不用软件隐藏重要文件
- 44.Linux君正X1000-添加st7789v显示
- jQuery的节点添加、删除、替换等操作
- 100以内与7有关的数(for和if)
- epoll, NIO,AIO
- 使用openssh-clients的scp命令来传输文件
热门文章
- python 之正则表达式
- CSS中padding、margin两个重要属性的详细介绍及举例说明
- 【Python图像特征的音乐序列生成】GitHub已经有人将mingus改到了Python3版本
- 使Win10用户获得特殊权限以便删除相应文件(夹)
- 日常-acm-三位数反转
- 2018.4.15 Mac系统下如何使用StartUml画好需求分析的类图 (同样适用于windows)
- 原型模式 -- JavaScript语言的灵魂
- Xcode中的Project和Target
- d3.js--03(增删改查)
- Angular - Can&#39;t bind to &#39;ngModel&#39; since it isn&#39;t a known property of &#39;input&#39;.