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 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- node里如何查看浏览器信息
'use strict'; let http = require(`http`); http.createServer((req, res) => { console.log(req.heade ...
- java 生成pdf报表
public void saveMapAddressInfo(String orderCode){ try{ List<Leads> leadses = leadsService.find ...
- 一些硬件厂商的MAC号
http://standards.ieee.org/develop/regauth/oui/oui.txt https://svn.nmap.org/nmap/nmap-mac-prefixes
- 如何设置MySQL Workbench EER Diagram 尺寸?
ER Diagram -> Model -> Diagram Properties and Size...
- PHPCMS V9 学习总结(转)
转自:http://www.cnblogs.com/Braveliu/p/5074930.html 在实现PHPCMS网站过程中,根据业务需求,我们遇到很多问题,特此总结如下,以便大家参考学习. [1 ...
- 刚接触js不久,自己写的banner幻灯片效果。
对于我这种菜鸟来讲,刚接触项目.叫我用插件,其实我说插件太臃肿不想用,倒不如说我是看不懂那些插件...- -(更愿意自己写点看得懂的代码,顺便也是个学习的过程) 所以自己花了些时间,自己来写了个dem ...
- 在Adobe Reader中保存PDF表单数据的方法
通常,Adobe Reader 用户填写表单后,是无法保存所填表单的副本的.但是,对于 Reader 8 和更高版本的用户,您可以扩展其权限,使他们可以完成此操作.如果您使用的是 Acrobat Pr ...
- 酷炫地给py代码标上行数
Python IDLE是没有显示行号的功能的,今天学了一个方式可以酷炫地给自己的代码加上行号,该方法直接修改代码,慎用哦!代码如下: import fileinput for line in file ...
- [待续]Async in C# 1
异步.异步是在.net .45里面提供的一个新的方法 它主要用在.三个方面 1.网络访问 2.磁盘访问 3.延迟很长时间的步骤 它主要有2个关键字 Async Await Async 怎么工作 d ...
- Ferry Loading||
uva10440:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...