CodeForces - 593A - O - 2Char - 暴力枚举
Posted Chivas_/Regal
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 593A - O - 2Char - 暴力枚举相关的知识,希望对你有一定的参考价值。
题目:
思路:
今天搞这个1200分的题,有点搞心态了
一个1200的题让我写出了1400的感受
(可能是我太菜了吧)
其实就枚举就行了
首先内部不同字符个数 > 2的都不能存
然后枚举要用哪两个字符
然后看这个字符串是不是只有枚举出来的两个字符之一或都有
至于查看这个字符串有哪些字符的方法:只需要把字符串排个序,内部存的字符就暴露在头和尾啦
代码:
/*
________ _ ________ _
/ ______| | | | __ | | |
/ / | | | |__| | | |
| | | |___ _ _ _ ___ _ _____ | ___| ______ _____ ___ _ | |
| | | __ \\ |_| | | | | | _\\| | | ____| | |\\ \\ | __ | | _ | | _\\| | | |
| | | | \\ | _ | | | | | | \\ | | \\___ | | \\ \\ | |_/ _| | |_| | | | \\ | | |
\\ \\______ | | | | | | \\ |_| / | |_/ | ___/ | | | \\ \\ | /_ \\__ | | |_/ | | |
Author : \\________| |_| |_| |_| \\___/ |___/|_| |_____| _________|__| \\__\\ |______| | | |___/|_| |_|
____| |
\\_____/
*/
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <stack>
#include <queue>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#define G 10.0
#define LNF 1e18
#define EPS 1e-6
#define PI acos(-1.0)
#define INF 0x7FFFFFFF
#define ll long long
#define ull unsigned long long
#define LOWBIT(x) ((x) & (-x))
#define LOWBD(a, x) lower_bound(a.begin(), a.end(), x) - a.begin()
#define UPPBD(a, x) upper_bound(a.begin(), a.end(), x) - a.begin()
#define TEST(a) cout << "---------" << a << "---------" << '\\n'
#define CHIVAS int main()
#define _REGAL exit(0)
#define SP system("pause")
#define IOS ios::sync_with_stdio(false)
#define map unordered_map
#define PB(x) push_back(x)
#define ALL(a) ((a).begin(),(a).end())
#define MEM(a, b) memset(a, b, sizeof(a))
#define EACH_CASE(cass) for (cin >> cass; cass; cass--)
#define LS l, mid, rt << 1
#define RS mid + 1, r, rt << 1 | 1
#define GETMID (l + r) >> 1
using namespace std;
template<typename T> inline T MAX(T a, T b){return a > b? a : b;}
template<typename T> inline T MIN(T a, T b){return a > b? b : a;}
template<typename T> inline void SWAP(T &a, T &b){T tp = a; a = b; b = tp;}
template<typename T> inline T GCD(T a, T b){return b > 0? GCD(b, a % b) : a;}
template<typename T> inline void ADD_TO_VEC_int(T &n, vector<T> &vec){vec.clear(); cin >> n; for(int i = 0; i < n; i ++){T x; cin >> x, vec.PB(x);}}
template<typename T> inline pair<T, T> MaxInVector_ll(vector<T> vec){T MaxVal = -LNF, MaxId = 0;for(int i = 0; i < (int)vec.size(); i ++) if(MaxVal < vec[i]) MaxVal = vec[i], MaxId = i; return {MaxVal, MaxId};}
template<typename T> inline pair<T, T> MinInVector_ll(vector<T> vec){T MinVal = LNF, MinId = 0;for(int i = 0; i < (int)vec.size(); i ++) if(MinVal > vec[i]) MinVal = vec[i], MinId = i; return {MinVal, MinId};}
template<typename T> inline pair<T, T> MaxInVector_int(vector<T> vec){T MaxVal = -INF, MaxId = 0;for(int i = 0; i < (int)vec.size(); i ++) if(MaxVal < vec[i]) MaxVal = vec[i], MaxId = i; return {MaxVal, MaxId};}
template<typename T> inline pair<T, T> MinInVector_int(vector<T> vec){T MinVal = INF, MinId = 0;for(int i = 0; i < (int)vec.size(); i ++) if(MinVal > vec[i]) MinVal = vec[i], MinId = i; return {MinVal, MinId};}
template<typename T> inline pair<map<T, T>, vector<T> > DIV(T n){T nn = n;map<T, T> cnt;vector<T> div;for(ll i = 2; i * i <= nn; i ++){while(n % i == 0){if(!cnt[i]) div.push_back(i);cnt[i] ++;n /= i;}}if(n != 1){if(!cnt[n]) div.push_back(n);cnt[n] ++;n /= n;}return {cnt, div};}
inline void solve(){
int n; cin >> n;
vector<string> vec;
string s;
for(int i = 0; i < n; i ++){
cin >> s;
sort(s.begin(), s.end());
map<char, int> mp;
int cnt = 0;
for(int j = 0; j < s.size(); j ++){
if(!mp[s[j]]) mp[s[j]] = 1, cnt ++;
}if(cnt <= 2) vec.push_back(s);
}
int res = 0;//维护最大值
for(char i = 'a'; i <= 'z'; i ++){
for(char j = i + 1; j <= 'z'; j ++){
int cur = 0;//当前答案
for(int k = 0; k < vec.size(); k ++){
if(vec[k][0] == vec[k][vec[k].size() - 1]){//头和尾一样的话整个字符串只有一个字符,看这个字符是不是枚举的其中之一
if(vec[k][0] == i || vec[k][0] == j)
cur += vec[k].size();
}else{//如果不一样说明有两个不同的字符,j比i大,所以头要等于i尾要等于j
if(vec[k][0] == i && vec[k][vec[k].size() - 1] == j)
cur += vec[k].size();
}
}
res = MAX(res, cur);
}
}
cout << res <<endl;
}
CHIVAS{
solve();
_REGAL;
}
以上是关于CodeForces - 593A - O - 2Char - 暴力枚举的主要内容,如果未能解决你的问题,请参考以下文章
CodeForces - 1501C Going Home(暴力)