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 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- Quartz.NET管理类
最近做项目设计到Quartz.NET,写了一个Quartz.NET管理类,在此记录下. public class QuartzManager<T> where T : class,IJob ...
- Web通信中的Get、Post方法
首先我们要了解Tomcat,Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选. ...
- anjularjs slider控件替代方案
做项目需要一个slider控件,找了很久没有找到合适的指令集,无意间看到可以直接用range替代,不过样式有点丑. <label> <input type="range&q ...
- 分享最近写的一个存储过程 SOLVE_LOCK
CREATE OR REPLACE PROCEDURE SOLVE_LOCK AS V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句V_SQL02 VARCHA ...
- 绘图quartz之加水印
实现在图片上加一个水印 并存在document的路径下 同时在手机相册中也存一份 //首先开启imageContext找到图片 UIGraphicsBeginImageContext( ...
- c#与c++交互的一些东西
最近做一个项目,对方公司只提供了一个c++的DLL,但没封住,c#无法DllImport.所以只能自己写c++来封住了. 对方的Dll只接收yuv420的图片格式,所以在c++里用opencv来转换. ...
- HttpClient的get+post请求使用
啥都不说,先上代码 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReade ...
- javascript--15条规则解析JavaScript对象布局(__proto__、prototype、constructor)
大家都说JavaScript的属性多,记不过来,各种结构复杂不易了解.确实JS是一门入门快提高难的语言,但是也有其他办法可以辅助记忆.下面就来讨论一下JS的一大难点-对象布局,究竟设计JS这门语言的人 ...
- js 的其它运算符和优先级
三元运算符: 语法为 exp1? exp2:exp3 判断 exp1是true 和 false 如果true,则返回exp2 ,如果false ,则返回exp3 <script> if ...
- int*-------int
a=(int)((int*)0 + 4)求a是多少 大家看图应该明白了 十六进制0x00000010转换为十进制就是16