UVA 257 - Palinwords

题目链接

题意:输出一个文本里面的palinword,palinword的定义为。包括两个不同的回文子串,而且要求回文子串不能互相包括

思路:对于每一个单词推断一次。因为不能互相包括。对于每一个位置。事实上就仅仅要找长度3和4的情况就可以,这样复杂度为O(n),至于推断反复的。就用hash就可以

代码:

#include <cstdio>
#include <cstring> char str[260];
int hash[555555], save[260], sn; bool check() {
sn = 0;
int n = strlen(str);
for (int i = 1; i < n - 1; i++) {
if (str[i - 1] == str[i + 1]) {
int num = (str[i - 1] - 'A' + 1) * 27 * 27 + (str[i] - 'A' + 1) * 27 + str[i + 1] - 'A' + 1;
if (!hash[num]) {
hash[num] = 1;
save[sn++] = num;
}
continue;
}
if (str[i] == str[i + 1] && str[i - 1] == str[i + 2]) {
int num = (str[i - 1] - 'A' + 1) * 27 * 27 * 27 + (str[i] - 'A' + 1) * 27 * 27 + (str[i + 1] - 'A' + 1) * 27 + str[i + 2] - 'A' + 1;
if (!hash[num]) {
hash[num] = 1;
save[sn++] = num;
}
}
}
for (int i = 0; i < sn; i++)
hash[save[i]] = 0;
return sn >= 2;
} int main() {
while (~scanf("%s", str))
if (check())
printf("%s\n", str);
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

UVA 257 - Palinwords(弦HASH)的更多相关文章

  1. UVA 257 Palinwords(hash)题解

    思路:给你字符串,如果他包含至少两个长度大于等于3的回文,并且这些回文不能嵌套(例如aaa嵌套在aaaa,waw嵌套在awawa),如果这个字符串这么牛逼的话,就输出他. 思路:拿到字符串先正序has ...

  2. UVa 11019 Matrix Matcher - Hash

    题目传送门 快速的vjudge传送门 快速的UVa传送门 题目大意 给定两个矩阵S和T,问T在S中出现了多少次. 不会AC自动机做法. 考虑一维的字符串Hash怎么做. 对于一个长度为$l$的字符串$ ...

  3. poj 2774 最长公共子--弦hash或后缀数组或后缀自己主动机

    http://poj.org/problem?id=2774 我想看看这里的后缀数组:http://blog.csdn.net/u011026968/article/details/22801015 ...

  4. HDOJ--4821--String【弦hash】

    联系:http://acm.hdu.edu.cn/showproblem.php?pid=4821 题意:给一个字符串,选m个长度为l的子串组成新的串.要求这m个子串互不同样,问有多少种组合. 字符串 ...

  5. UVA - 11019 Matrix Matcher hash+KMP

    题目链接:传送门 题解: 枚举每一行,每一行当中连续的y个我们hash 出来 那么一行就是 m - y + 1个hash值,形成的一个新 矩阵 大小是 n*(m - y + 1), 我们要找到x*y这 ...

  6. Acdreamoj1116(Gao the string!)弦hash+二分法+矩阵高速功率

    Problem Description give you a string, please output the result of the following function mod 100000 ...

  7. UVA 10887 set或hash

    题意: 给出n个A串和m个B串,将这A串与B串连接(B接在A后面)可以生成n*m个AB串,求不同的AB串的数量 分析: set直接水过 #include <bits/stdc++.h> u ...

  8. 学习Word2vec

    有感于最近接触到的一些关于深度学习的知识,遂打算找个东西来加深理解.首选的就是以前有过接触,且火爆程度非同一般的word2vec.严格来说,word2vec的三层模型还不能算是完整意义上的深度学习,本 ...

  9. 机器学习算法实现解析——word2vec源代码解析

    在阅读本文之前,建议首先阅读"简单易学的机器学习算法--word2vec的算法原理"(眼下还没公布).掌握例如以下的几个概念: 什么是统计语言模型 神经概率语言模型的网络结构 CB ...

随机推荐

  1. vmware: The file system upon which * resides is critically low on free space.

    The file system upon which ******.localized/Windows XP Professional.vmwarevm' resides is critically ...

  2. Java中读取某个目录下的所有文件和文件夹

    import java.io.File; public class Test1 { public static void main(String[] args) { String path=" ...

  3. jquery 弹出登陆框,简单易懂!修改密码效果代码

    在网上找了一大堆,看的眼花瞭乱,还是研究原码,自已搞出来了! ui原地址:http://jqueryui.com/dialog/#modal-form 可以把js,css下载到本地,要不然不联网的话, ...

  4. 该Tiled地图制作拿到项目~~这是偷懒,为了直接复制后写来

    1.现在,.h声明private: cocos2d::CCSprite* ninja; cocos2d::CCTMXTiledMap*  tileMap; 然后.cpp中增加tileMap = CCT ...

  5. friend keyword 对于模板 并不只不过友元!!!

    friend是C++中封装的漏网之鱼. C++中的friend同意其它的类或者是函数訪问本类的不论什么成员.甚至是private成员,仅仅要该类声明其为友元. 但是,在有些情况下,并非同意外界訪问类的 ...

  6. 【NOIP2002】矩形覆盖 DFS

    首先,我喜欢愤怒搜索,因为尽管说K<=4,的确K小于或等于3的. 当然某些K<=3还600ms的我就不加评论了. 好吧,可是怎么搜呢?我们考虑到矩形数量非常少,所以能够怒搜矩形. 一些神做 ...

  7. Java乔晓松-android中上传图片到服务器Tomcat(Struts2)

    在做android开发的时候,有时你会用到图片的上传功能,在我的android项目中,我是选中图片,点击上传多张图片 android客户端上传图片部分的代码如下: package com.exampl ...

  8. The practice program of C on point

    //字符反向排列 //vision 1.2 #include<stdio.h> void reverse_string( char *str ) { char *string;//第一个字 ...

  9. C# The process cannot access the file because it is being used by another process

    C# The process cannot access the file because it is being used by another process   The process cann ...

  10. 重新想象 Windows 8 Store Apps (24) - 文件系统: Application Data 中的文件操作, Package 中的文件操作, 可移动存储中的文件操作

    原文:重新想象 Windows 8 Store Apps (24) - 文件系统: Application Data 中的文件操作, Package 中的文件操作, 可移动存储中的文件操作 [源码下载 ...