TC SRM 607 DIV2
求拼接完成后的字符串包含的子回文串的数目,一开始还用暴力去做,想都不用想 肯定超时了。
复习了一下求最长子回文串的算法,发现可以类似解决。
给相邻字符之间添加一个‘@’字符,这样所有的回文串都是奇数长度,然后从左到右,统计以每个字符为中心的回文串的数目就行了,长度逐渐递增,一旦遇到不是回文串的情况,就马上结束,开始对下一个字符为中心的回文串的统计。
Orz…这个回文串算法不久前学过,最近搞前面基础去了就忘得差不多了,还是太弱了,继续好好努力,先打好基础,同时学点新东西,我就不相信,acm这东西花时间是搞不好的。
代码:
int count(vector <string> S1, vector <string> S2){
string tempstr = "", str = "";
int n1= S1.size(), n2 = S2.size();
REP(i, n1)
tempstr+= S1[i];
REP(i, n2)
tempstr+= S2[i];
int ans = 0;
int len = tempstr.size();
str += '@';
REP(i, len)
{
str += tempstr[i];
str += '@';
}
cout<<str<<' '<<str.size()<<endl;
len = 2*len+1;
REP(i, len) REP(k, inf){
if(!(i + k < len && i - k >= 0))
break;
if(str[i+k] == str[i-k])
ans += (str[i+k]!='@');
else break; }
return ans;
}
TC SRM 607 DIV2的更多相关文章
- TC SRM 663 div2 B AABB 逆推
AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many En ...
- TC SRM 663 div2 A ChessFloor 暴力
ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a squa ...
- TC SRM 665 DIV2 A LuckyXor 暴力
LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive int ...
- TC SRM 593 DIV2 1000
很棒的DP,不过没想出,看题解了..思维很重要. #include <iostream> #include <cstdio> #include <cstring> ...
- TC SRM 591 DIV2 1000
很不错的一题,非常巧妙的用DP顺序解决这个问题... 可以发现,只和A里面最小的有关系... #include <cstdio> #include <cstring> #inc ...
- tc srm 636 div2 500
100的数据直接暴力就行,想多了... ac的代码: #include <iostream> #include <cstdio> #include <cstring> ...
- TC SRM 664 div2 B BearPlaysDiv2 bfs
BearPlaysDiv2 Problem Statement Limak is a little bear who loves to play. Today he is playing by ...
- TC SRM 664 div2 A BearCheats 暴力
BearCheats Problem Statement Limak is an old brown bear. Because of his bad eyesight he sometime ...
- TC SRM 665 DIV2 B LuckyCycle 暴力
LuckyCycleTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.ac ...
随机推荐
- 【转】The content of element type "configuration" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?...
[转]The content of element type "configuration" must match "(properties?,settings?,typ ...
- h2database源码浅析:锁与MVCC
Table Level Locking The database allows multiple concurrent connections to the same database. To mak ...
- apache http server 多线程模式
一般apache采用prefork和worker机制,通过apachectl -l命令查看默认使用的prefork机制.需要修改prefork策略 那么需要做如下修改: 1,/usr/local/ap ...
- Operation not allowed for reason code "7" on table 原因码 "7"的解决
对表进行任何操作都不被允许,提示SQLSTATE=57016 SQLCODE=-668 ,原因码 "7"的错误:SQL0668N Operation not allowed for ...
- HttpClient Post Get请求方法,留在以后可能会用到
/// <summary> /// Post请求返回实体 /// </summary> /// <param name="url">请求地址&l ...
- 用VIM写作
Write in VIm 1.Writing in Vim by Dr. Bunsen
- WIX Custom Action (immediate, deffered, rollback)
Following content is directly reprinted from From MSI to WiX, Part 19 - The Art of Custom Action, Pa ...
- InstallShield : 如何查找编译后的 Merge Module存放路径
工程菜单栏中依次选择 Tools ---> Options… ,选择 Merge Modules tab 页,如下,就会看到Merge Module的存放路径,也可以根据需求修改. Merge ...
- 水题~~~~HDU 4788
Description Yesterday your dear cousin Coach Pang gave you a new 100MB hard disk drive (HDD) as a gi ...
- 九度OJ 1447 最短路 1008 最短路径问题
题目地址:http://ac.jobdu.com/problem.php?pid=1447 题目描述: 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上 ...