UVALive6659 - Dromicpalin Substrings

题意

给一个字符串,找出其子串可化为回文串的个数,子串可以任意改变其顺序。

思路

遍历每一个子串,若子串长度为奇数且只有一个字母的个数为奇数 或 字串长度为偶数且所有字母个数为偶数,则此子串为所求串。

总结

刚开始漏看了题,导致题意读错。

挺简单一道题,比赛时不记得怎样遍历每个子串。

对自己有点信心。加油。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 int T, kase = 0;
 6 int num[30];
 7 int main()
 8 {
 9     //freopen("in.txt","r",stdin);
10     cin >> T;
11     while(T--) {
12         string s;
13         cin >> s;
14         int len = s.size();
15         int ans = 0;
16         for(int i = 0; i < len; i++) {
17             ans++;
18             memset(num,0,sizeof num);
19             num[s[i]-‘a‘]++;
20             int odd = 1;
21             for(int j = i + 1; j < len; j++) {
22                 if((++num[s[j]-‘a‘]) % 2) odd++;
23                 else odd--;
24                 if((!odd && (j-i)%2) || (odd == 1&& (j-i)%2 == 0)) ans++;
25             }
26         }
27         cout << "Case " << ++kase << ": " << ans << endl;
28     }
29     return 0;
30 }
时间: 2024-08-10 15:08:48

UVALive6659 - Dromicpalin Substrings的相关文章

UVA 12718 Dromicpalin Substrings(寻找字符串连续子串的回文)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4456 题意:寻找给出字符串的字串中是回文的个数(注意:字串中字母换位置后能组成回文也要算在内,例如:aab之类的可以换位置为:aba 也是一个回文). 思路:只需统计每个字母出现的次数,再统计出现次数中

[Leetcode] DP-- 467. Unique Substrings in Wraparound String

Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....". Now we have another string p. Your job is to find

uva 10829 - L-Gap Substrings(后缀数组)

题目链接:uva 10829 - L-Gap Substrings 题目大意:给定一个字符串,问有多少字符串满足UVU的形式,要求U非空,V的长度为g. 解题思路:对字符串的正序和逆序构建后缀数组,然后枚举U的长度l,每次以长度l分区间,在l和l+d+g所在的两个区间上确定U的最大长度. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using nam

[LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd....". Now we have another string p. Your job is to find

POJ 3415 Common Substrings (求长度不小于k的公共子串的个数)

Common Substrings Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 10002   Accepted: 3302 Description A substring of a string T is defined as: T(i, k)=TiTi+1...Ti+k-1, 1≤i≤i+k-1≤|T|. Given two strings A, B and one integer K, we define S,

字符串(后缀数组):POJ 3415 Common Substrings

Common Substrings Description A substring of a string T is defined as: T(i, k)=TiTi+1...Ti+k-1, 1≤i≤i+k-1≤|T|. Given two strings A, B and one integer K, we define S, a set of triples (i, j, k): S = {(i, j, k) | k≥K, A(i, k)=B(j, k)}. You are to give

SPOJ 题目694 Distinct Substrings(后缀数组,求不同的子串个数)

DISUBSTR - Distinct Substrings no tags Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T<=20; Each test case consists of one string, whose length is <= 1000 Output For each test case output

解题报告 之 POJ1226 Substrings

解题报告 之 POJ1226 Substrings Description You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings. Input The first li

SPOJ 705 New Distinct Substrings

New Distinct Substrings Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on SPOJ. Original ID: SUBST164-bit integer IO format: %lld      Java class name: Main Given a string, we need to find the total number of its distinct subst