ICode9

精准搜索请尝试: 精确搜索
  • Longest Palindrome(C++最长回文串)2020-12-01 09:31:51

    解题思路: (1)记录每个字母出现的次数,偶数均可以组成回文,中间只能放字符为奇数的字符串 class Solution { public: int longestPalindrome(string s) { int count=0; unordered_map<char,int> mp; for(int i=0;i<s.length();i++) { mp[s[i

  • 1312. Minimum Insertion Steps to Make a String Palindrome2020-11-15 12:34:30

    问题: 给定一个字符串,求最少添加几个字母,能使的字符串成为回文字符串。 Example 1: Input: s = "zzazz" Output: 0 Explanation: The string "zzazz" is already palindrome we don't need any insertions. Example 2: Input: s = "mbadm" Output: 2 Explanation: Stri

  • 【NOIP2017提高A组模拟9.12】Arrays and Palindrome2020-11-14 17:02:20

    【NOIP2017提高A组模拟9.12】Arrays and Palindrome[SPJ] 题目 Description Input Output Sample Input 1 6 Sample Output 6 2 1 5 Data Constraint 题解 题意 em……语言组织能力不行,看题吧 题解 结论题 可以证得\(A\)里最多只有2个奇数,否则无解 分情况讨论 0个奇数:\(a\)就

  • LeetCode 234 - Palindrome Linked List (Easy)2020-11-09 09:36:02

    Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true方法:先把linked list分成两半之后,reverse the second half。然后比较两半的node的值。time complexity:O(n) space complexity:O(1)

  • 题解 P6754 【[BalticOI 2013 Day1] Palindrome-Free Numbers】2020-10-28 19:31:53

    分析: 这道题看着像是\(\;\text{manacher}\)(马拉车),但其实是数位dp。 如果某个数上的某一位与它的上一位相同,则这个数肯定是个回文数。 同理,如果某个数上的某一位与它的上上一位相同,则这个数肯定也是个回文数。 数位dp时要注意前导0的判断。 时间复杂度大概是 \(O(\log(n)\times10

  • 2017哈尔滨ccpc2020-10-24 22:32:31

    这套题感觉出的很好 都是比较考察思维的 55 / 239 A HDU 6230 Palindrome !!! 53 / 219 B HDU 6231 K-th Number !!! 5 / 32 C HDU 6232 Confliction !!! 7 / 11 D HDU 6233 X-Men !!! 0 / 9 E HDU 6234 Square Network ??? 190 / 237 F HDU 6235 Permutation --- 0 / 8 G HDU 623

  • Tokitsukaze, CSL and Palindrome Game2020-08-16 10:00:49

    1001 Tokitsukaze, CSL and Palindrome Game 比较字典序的时候考虑树上倍增,用树上倍增的时候要保证路径相同,所以把路径哈希一下,直接比较即可 但是当我把maxn开到1e5+5的时候很奇怪的就wa了,开到1e5+20才过 // Created by CAD #include <bits/stdc++.h> #define ll long long usin

  • leecode 140:palindrome-number2020-08-12 14:32:31

    题目描述 在不使用额外的内存空间的条件下判断一个整数是否是回文数字 提示: 负整数可以是回文吗?(比如-1) 如果你在考虑将数字转化为字符串的话,请注意一下不能使用额外空间的限制 你可以将整数翻转。但是,如果你做过题目 反转数字 你会知道将整数翻转可能会出现溢出的情况,你

  • 131. Palindrome Partitioning2020-05-31 18:08:44

    package LeetCode_131 /** * 131. Palindrome Partitioning * https://leetcode.com/problems/palindrome-partitioning/description/ * * Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome

  • python统计英文文本中的回文单词数2020-05-13 21:03:55

    1. 要求: 给定一篇纯英文的文本,统计其中回文单词的比列,并输出其中的回文单词,文本数据如下: This is Everyday Grammar. I am Madam Lucija And I am Kaveh. Why the title, Lucija? Well, it is a special word. Madam? Yeah, maybe I should spell it for you forward or backward?

  • LeetCode 680. 验证回文字符串 Ⅱ [Valid Palindrome II (Easy)]2020-05-12 10:58:48

    给定一个非空字符串 s,最多删除一个字符。判断是否能成为回文字符串。 来源:力扣(LeetCode)   回文字符串,是指具有左右对称特点的字符串,例如 "abcba" 就是一个回文字符串。 这种判断方式刚好相当于一次跳过机会。 class Solution { public: bool validPalindrome(string s) {

  • Gym101237C The Palindrome Extraction Manacher2020-05-02 20:54:42

    题意 给定字符串\(S\),分段\(S=A+B+C+D+E\),\(A,B,C,D,E\)可以为空串。要求方案\(B+D\)为回文串,且\(|B+D|\)最大 做法 假设\(|B|>|D|\),则\(B=rev(D)+T\),\(T\)为某回文串 跑manacher,对于一组\([l,i,r]\),就是找\(S_{1,l-1}\)的一组最长后缀使得其在\(S_{r+1,n}\)作为子串出现 具体做

  • Codeforces 932G Palindrome Partition2020-05-01 23:52:31

    题意 给你一个长为\(n\)的字符串\(S\),现在你要把他划分成\(k\)段,记为\(p_1p_2…p_k\),其中对于任意\(1<=i<=k\),满足\(p_i=p_k−i−1\),且\(k\)为偶数。问划分方案数。 n<=1e6 做法 将\(S=s_1s_2s_3...s_{n-2}s_{n-1}s_n\),转化成\(S'=s_1s_ns_2s_{n-1}s_3s_{n-2}...\),这样问题就变

  • Codeforces Round #636 (Div. 3) D. Constant Palindrome Sum2020-04-22 22:01:51

    完整代码如下: #include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int a[N]; int s[N<<1]; int main() { int T; cin>>T; while(T--) { memset(s, 0, sizeof s); int n, k; cin>>n>>k; int r

  • D. Constant Palindrome Sum(分情况讨论+差分)2020-04-22 18:53:16

    题目 题意:给出n(2e5)个数,可以修改某个数为\(1\:to\:k\)(2e5),问最少几次修改使\(i\in1\:to\:\frac{n}{2}\),\(满足a[i] + a[n-i+1] = x\) 解法:差分维护取某个值为定值时所需要的最少操作次数。 对于每一对数令sum = a[i]+a[n-i+1] , l = min(a[i] , a[n-i+1])+1 , r = max(a[i] ,

  • Codeforces Round #636div3 D. Constant Palindrome Sum2020-04-22 12:59:31

                                                                                              题意:给你一个长度为偶数n的数组,每次可以将一个元素修改为不大于k的值,要求每个a[i]+a[n-i+1]都相等,求最少操作多少次   题解:假设

  • Codeforces Global Round 7 D2. Prefix-Suffix Palindrome (Hard version)(Manacher算法+输出回文字符串)2020-04-18 13:01:54

    This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task. You are given a string ss, consisting of lowercase Eng

  • Codeforces Round #634 (Div. 3) E —Three Blocks Palindrome2020-04-16 13:58:43

    补题 参考:https://blog.csdn.net/weixin_45750972/article/details/105523046 #include <vector> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 210, M = 2e5+10; //a[j,i

  • codeforces-1335-E Three Blocks Palindrome2020-04-14 21:56:38

    codeforces-1335-E Three Blocks Palindrome 传送门: easy:https://codeforces.com/contest/1335/problem/E1 hard:https://codeforces.com/contest/1335/problem/E2 题意: 定义 three blocks palindrome 为 aaaaabbbaaaaa,其中两边的a必须个数相等 而且序列中只存在两种元素 1 1 1

  • UVA 401 回文词2020-04-11 12:00:12

    问题描述:      代码展示: 1 #include<stdio.h> 2 #include<string.h> 3 #include<ctype.h> 4 const char* rev="A 3 HIL JM O 2TUVWXY51SE Z 8 ";//注意空格数和非法镜像的个数对应 5 const char* msg[] = {"not a palindrome","a regula

  • 234. Palindrome Linked List2020-03-29 23:07:26

    Problem: Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false Example 2: Input: 1->2->2->1 Output: true Follow up: Could you do it in O(n) time and O(1) space? 思路: Solution (C++): bool isPalindrom

  • LeetCode 409. Longest Palindrome2020-03-19 09:53:16

    409. Longest Palindrome(最长回文串) 链接 https://leetcode-cn.com/problems/longest-palindrome/ 题目 给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串。 在构造过程中,请注意区分大小写。比如 "Aa" 不能当做一个回文字符串。 注意: 假设字符串的长

  • LeetCode 234. Palindrome Linked List2020-03-18 14:04:54

    234. Palindrome Linked List(回文链表) 链接 https://leetcode-cn.com/problems/palindrome-linked-list 题目 请判断一个链表是否为回文链表。 示例 1: 输入: 1->2 输出: false 示例 2: 输入: 1->2->2->1 输出: true 进阶: 你能否用 O(n) 时间复杂度和 O(1) 空间复杂度解决此题? 思

  • B - Yet Another Palindrome Problem的简单方法2020-03-17 13:04:10

    You are given an array aa consisting of nn integers. Your task is to determine if aa has some subsequence of length at least 33 that is a palindrome. Recall that an array bb is called a subsequence of the array aa if bb can be obtained by re

  • B. Yet Another Palindrome Problem2020-03-16 12:53:35

    B. Yet Another Palindrome Problem 题意 在一个字符串中,能否找到一个长度为3的回文子串。 思路 O(n^2)暴力枚举。 代码实现 #include<bits/stdc++.h> using namespace std; int main(void){ int t; cin >> t; while(t--){ int n; cin >> n;

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有