CodeForces 593A
题目链接:
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的更多相关文章
- CodeForces - 593A -2Char(思维+暴力枚举)
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is th ...
- CodeForces 593A 2Char
暴力. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> u ...
- Codeforces Round #329(Div2)
CodeForces 593A 题意:n个字符串,选一些字符串,在这些字符串中使得不同字母最多有两个,求满足这个条件可选得的最多字母个数. 思路:用c[i][j]统计文章中只有i,j对应两个字母出现的 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- 表达式:使用API创建表达式树(2)
一.BlockExpression类:表式一个包含可在其中定义变量的表达式序列的块.是一组表达式,类似于多个委托的 += 后的效果,其返回表达式是最后一个表达式决定.以下是BlockExpressio ...
- HTML5 canvas createRadialGradient()放射状/圆形渐变
定义和用法 createLinearGradient() 方法创建放射状/圆形渐变对象. 渐变可用于填充矩形.圆形.线条.文本等等. 提示:请使用该对象作为 strokeStyle 或 fillSty ...
- MVC+EF 的增删改查操作
1. //创建EF映射对象数据集 static Models.db_JiaoYouEntities DbDeleteData = new Models.db_JiaoYouEntities(); 2. ...
- padding and margin.
padding is the space between the content and the border, whereas margin is the space outside the bor ...
- C#中邮件的发送基本操作
本地配置的邮箱:http://localhost:6080/index.php //邮件的收发需要用到两个类 //1.用来创建一封邮件对象 //1.MailMessage 添加对 usin ...
- NgNice项目案例
技术构架: 服务端技术:NodeJS + Express4.x + Mongodb + Mongoose 前端技术: AngularJS1.2.x + Bootstrap3.x 源码:https:// ...
- Orace数据库锁表的处理与总结<摘抄与总结一>
TM锁(表级锁)类型共有5种,分别称为共享锁(S锁).排它锁(X锁).行级共享锁(RS锁).行级排它锁(RX锁).共享行级排它锁(SRX锁) 当Oracle执行DML语句时,系统自动在所要操作的表上申 ...
- IOS-UI-UILable
//用于文本展示 UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 200, 300)]; //使用测色器自选颜色 ...
- 如何获取App当前版本号
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; NSString *currentVersion = [infoDic ...
- spring data jpa Specification 例子
/** * 封装查询条件 * * @param baseQueryDTO * @return */ private Specification<ActivityBase> getSpeci ...