如果自己是回文串可以做中心

如果一个串和另一个串的转置相等则可以凑一对

优先配对

#include <bits/stdc++.h>
using namespace std; int n,m,u[105];
string str[105];
vector <int> a,b; signed main() {
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>str[i];
int ans=0;
for(int i=1;i<=n;i++) {
if(u[i]) continue;
for(int j=i+1;j<=n;j++) {
int flag=1;
for(int k=0;k<m;k++) if(str[i][k]!=str[j][m-k-1]) flag=0;
if(flag) {
u[i]=1;
u[j]=1;
a.push_back(i);
b.push_back(j);
ans+=2;
break;
}
}
}
int flag=0;
for(int i=1;i<=n;i++) {
int tmp=1;
for(int k=0;k<m;k++) if(str[i][k]!=str[i][m-k-1]) tmp=0;
if(tmp) flag=i;
}
if(flag) ++ans;
cout<<ans*m<<endl;
for(int i=0;i<a.size();i++) cout<<str[a[i]];
cout<<str[flag];
for(int i=b.size()-1;i>=0;--i) cout<<str[b[i]];
}

[CF1034B] Longest Palindrome - 贪心的更多相关文章

  1. [LeetCode] Longest Palindrome 最长回文串

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  2. 409. Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  3. LeetCode 409 Longest Palindrome

    Problem: Given a string which consists of lowercase or uppercase letters, find the length of the lon ...

  4. LeetCode Longest Palindrome

    原题链接在这里:https://leetcode.com/problems/longest-palindrome/ 题目: Given a string which consists of lower ...

  5. 每天一道LeetCode--409 .Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  6. 24. leetcode 409. Longest Palindrome

    409. Longest Palindrome Given a string which consists of lowercase or uppercase letters, find the le ...

  7. [Swift]LeetCode409. 最长回文串 | Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

  8. 【leetcode】409. Longest Palindrome

    problem 409. Longest Palindrome solution1: class Solution { public: int longestPalindrome(string s) ...

  9. [LeetCode&Python] Problem 409. Longest Palindrome

    Given a string which consists of lowercase or uppercase letters, find the length of the longest pali ...

随机推荐

  1. Java Lamada

    Collection: ->stream:返回一个以 colleciotn 元素为数据源的数据流. -->map: 入参 Function 对象,将此流中的元素依次作用于传入的 Funct ...

  2. Centos7 使用Docker 部署mssql 2017

    mssql是.NET的标配,一般使用.NET的人基本都用mssql. 以前mssql只能支持windows平台,从微软打出 拥抱开源 的口号开始,mssql的2017 版本,开始支持linux系统. ...

  3. 详细讲解Codeforces Round #624 (Div. 3) E. Construct the Binary Tree(构造二叉树)

    题意:给定节点数n和所有节点的深度总和d,问能否构造出这样的二叉树.能,则输出“YES”,并且输出n-1个节点的父节点(节点1为根节点). 题解:n个节点构成的二叉树中,完全(满)二叉树的深度总和最小 ...

  4. C++ 实现string转BYTE

    用于将形如"0x1A"的string转成BYTE类型 代码如下, 有问题欢迎指出 bool str2byte(const std::string &str, BYTE &a ...

  5. css 隐藏滚动条

    如何使用css隐藏滚动条 如何隐藏滚动条,同时仍然可以在任何元素上滚动? 首先,如果需要隐藏滚动条并在内容溢出时显示滚动条,只需要设置overflow:auto样式即可.想要完全隐藏滚动条只需设置ov ...

  6. springboot专用的注解

    这些是springboot特有的,常见的条件依赖注解有: @ConditionalOnBean,仅在当前上下文中存在某个bean时,才会实例化这个Bean. @ConditionalOnClass,某 ...

  7. C语言 putchar

    C语言 putchar putchar主要功能是输出一个char.可以根据ASLL号码输出对应字符 案例 #define _CRT_SECURE_NO_WARNINGS #include <st ...

  8. 两行配置完全解放gradle编译慢问题

    Android Studio编译经常出现gradle编译缓慢甚至超时问题,抛开电脑硬件配置不说,主要问题还是国内网络环境的因素影响,可以通过修改项目根目录下的build.gradle文件如下: bui ...

  9. 初始socket编程

    服务端语法 import socket # 导入套接字模块# 生成一个socket对象进行网络编程操作server = socket.socket(family=socket.AF_INET, typ ...

  10. 剑指offer-面试题53_1-在排序数组中查找数字-二分查找

    /* 题目: 统计一个数字在排序数组中出现的次数. */ /* 思路: 1.从前往后遍历,时间复杂度O(n). 2.二分查找到目标数字target,向前向后遍历,时间复杂度O(n). 3.利用二分法, ...