题目链接:

http://codeforces.com/problemset/problem/593/A

题意:

给你n个字符串,字符串只包含小写字母,从中选取任意个字符串,拼成一封信,这封信中至多有两种字符,输出信的最大长度。

题解:对a~z进行编号为1~26,开一个二维数组a,a[i][j]表示出现第i个字母和第j个字母的长度,对所有的字符串进行处理,然后就可以对数组a进行扫描:

len=max(a[i][j]+a[j][i]+a[i][0]+[j][0]) ;(0<i<27,i<j<27)

解题思路:

我觉得重点在这

for(i=0;i<len;i++)
{
if(!vis[s[i]-'a'])
{
vis[s[i]-'a']=1;
pos[ans++]=s[i]-'a';
}
if(ans>2) break;
}
if(i==len) a[pos[0]+1][pos[1]+1]+=len;

程序代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
using namespace std;
#define LL long long int MAX(int x,int y)
{
if(x>y) return x;
else return y;
}
int main()
{
int n,ans,sum,i,j,a[][],v[],len,f[];
char str[+];
cin>>n;
memset(a,,sizeof(a));
while(n--)
{
cin>>str;
len=strlen(str);
ans=;
memset(v,,sizeof(v));
memset(f,-,sizeof(f));
for(j=;j<len;j++)
{
if(!v[str[j]-'a'])
{
v[str[j]-'a']=;
f[ans++]=str[j]-'a';
}
if(ans>) break;
}
if(j==len)
a[f[]+][f[]+]+=len;
} sum=;
for(i=;i<;i++)
for(j=i+;j<;j++)
sum=MAX(sum,a[i][j]+a[j][i]+a[i][]+a[j][]);
cout<<sum<<endl;
return ;
}

CodeForces 593A的更多相关文章

  1. CodeForces - 593A -2Char(思维+暴力枚举)

    Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is th ...

  2. CodeForces 593A 2Char

    暴力. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> u ...

  3. Codeforces Round #329(Div2)

    CodeForces 593A 题意:n个字符串,选一些字符串,在这些字符串中使得不同字母最多有两个,求满足这个条件可选得的最多字母个数. 思路:用c[i][j]统计文章中只有i,j对应两个字母出现的 ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. Oracle数据导入导出imp/exp命令总结

    racle数据导入导出imp/exp就相当于oracle数据还原与备份.exp命令可以把数据从远程数据库服务器导出到本地的dmp文件,imp命令可以把dmp文件从本地导入到远处的数据库服务器中. 利用 ...

  2. winform(C#)拖拽实现获得文件路径

    设置Form的AllowDrop为true  private void Form1_DragDrop(object sender, DragEventArgs e)        {          ...

  3. Java反射学习(java reflect)(一)

    具有能够分析类能力的程序被称为反射,使用反射库可以编写能够动态操纵Java代码的程序. 一.开始 背景:Java运行时系统始终对所有对象维护一个被称为Runtime的类型标识,然后这货save着每个对 ...

  4. 原型链和new

    http://www.cnblogs.com/objectorl/archive/2010/01/11/Object-instancof-Function-clarification.html 构造器 ...

  5. java中的异常结构

    1.基类为Throwable. 2.Error和Exception分别继承Throwable. 3.Error类异常描述了Java运行系统中的内部错误以及资源耗尽的情形.应用程序不应该抛出这种类型的对 ...

  6. php里 \r\n换行问题

    <?php echo "hello"; echo "\r\n"; echo "world"; ?> 在浏览器输出的是hello ...

  7. python 图片压缩存储

    python(PIL)图像处理(等比例压缩.裁剪压缩) 缩略(水印)图 http://outofmemory.cn/code-snippet/12264/python-PIL-image-proces ...

  8. Resilio-sync auto restart

    syncheck.sh #!/bin/sh if [ $(pgrep xxxrslsync) ]; then echo && date >> /home/pi/sync/s ...

  9. java项目导出jar文件时指定main方法的类

    需要先运行一下main函数,eclipse的Export-->Runnable JAR File ---> 下的Launch configuration下拉列表才会有记录.如果想要删除下拉 ...

  10. O-C浮点数转化整数

    1.简单粗暴,直接转化 float f = 1.5; int a; a = (int)f; NSLog("a = %d",a); 输出结果是1.(int)是强制类型转化,丢弃浮点数 ...