HDU 4886 TIANKENG’s restaurant(Ⅱ) hash+dfs
题意:
1、找一个字符串s使得 s不是给定母串的子串
2、且s要最短
3、s在最短情况下字典序最小
hash。,,结果t掉了。。。加了个姿势怪异的hash值剪枝才过。。
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
#define N 1000100
#define ll long long
#define mod 2496764
char s[N];
short h[8][mod], tim;
bool f = false;
bool dfs(ll top, ll siz, ll dep) {
if (siz > 1000000) return false;
if(top == dep)
{
for(ll i = 0; i < 8; i++)
{
if(h[top][siz * 8 + i] != tim)
{
s[top] = i + 'A';
s[top+1] = 0;
f = true;
return true;
}
}
return false;
}
for(ll i = 0; i < 8; i++)
{
s[top] = i + 'A';
if(dfs(top+1, siz * 8 + i, dep))return true;
}
return false;
} int main(){
int i, j, T; scanf("%d",&T);
tim = 0; while(T--) {
tim ++;
scanf("%s", s);
f = false;
for(i = 0; s[i]; i++)
{
ll ans = 0;
for(j = 0; j < 7 && s[i+j]; j++)
{
ans = ans * 8 + s[i + j] - 'A';
h[j][ans] = tim;
}
} for(i = 0; i < 8; i++)
if(dfs(0, 0, i))break;
puts(s);
}
return 0;
}
HDU 4886 TIANKENG’s restaurant(Ⅱ) hash+dfs的更多相关文章
- HDU 4886 TIANKENG’s restaurant(Ⅱ) ( 暴力+hash )
TIANKENG’s restaurant(Ⅱ) Time Limit: 16000/8000 MS (Java/Others) Memory Limit: 130107/65536 K (Ja ...
- HDU 4883 TIANKENG’s restaurant Bestcoder 2-1(模拟)
TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/O ...
- HDU 4883 TIANKENG’s restaurant
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4883 解题报告:一家餐馆一天中有n波客人来吃饭,第 i 波 k 客人到达的时间是 s ,离开时的时间 ...
- HDU 4883 TIANKENG’s restaurant (贪心)
链接:pid=4883">带我学习.带我飞 第一次BC,稳挂,WA n多次.今天又一次做了一下 略挫 #include <iostream> #include <cs ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- hdoj 4883 TIANKENG’s restaurant【贪心区间覆盖】
TIANKENG’s restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/O ...
- hdu 4885 TIANKENG’s travel(bfs)
题目链接:hdu 4885 TIANKENG's travel 题目大意:给定N,L,表示有N个加油站,每次加满油能够移动距离L,必须走直线,可是能够为斜线.然后给出sx,sy,ex,ey,以及N个加 ...
- HDOJ 4883 TIANKENG’s restaurant
称号: TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Ja ...
- HDU 1078 FatMouse and Cheese ( DP, DFS)
HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, k] 步, 从 ( ...
随机推荐
- 去掉a标签的虚线框,避免出现奇怪的选中区域
a{blr:expression(this.onFocus=this.blur())}/*去掉a标签的虚线框,避免出现奇怪的选中区域*/
- Letter Combinations of a Phone Number——简单的回溯算法
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- 使用php后台给自己做一个页面路由,配合ajax实现局部刷新。
今天就要放假了,把近来囤积的小玩意儿总结整理一下. 在请求一个html页面来嵌入到当前页会有一个问题,就是跟随请求过来的html他的样式表和脚本会失效.是因为文档加载的先后顺序等问题造成的.因此,加载 ...
- CentOS7单机部署lamp环境和apache虚拟主机
(1)apache介绍 apache : httpd.apache.org 软件包:httpd 端口服务:80/tcp(http) 443/tcp(https,http+ssl) 配置文件: /etc ...
- es6字符串、数值、Math的扩展总结
字符串的扩展 1.for...of遍历字符串 2.includes()判断字符串中是否包含某个字符串,返回bool 3.startsWith(),endsWith()分别盘对字符串的头部和尾部是否含有 ...
- CF 某套题 O :Grid (简单BFS)
题意: 从左上角跳到右下角最少需要多少步,跳的规则为:可以向四个方向的任意一个方向跳当前格子中的步数,若跳不到右下角输出IMPOSSIBLE. 题解: BFS搜索,注意判断边界,标记. 代码: #in ...
- LOJ #6285. 数列分块入门 9-分块(查询区间的最小众数)
#6285. 数列分块入门 9 内存限制:256 MiB时间限制:1500 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: hzwer 提交提交记录统计测试数据讨论 2 题目描述 给 ...
- 203. Remove Linked List Elements【Easy】【未排序链表删除其中的给定值】
Remove all elements from a linked list of integers that have value val. Example: Input: 1->2-> ...
- Bzoj4016/洛谷P2993 [FJOI2014] 最短路径树问题(最短路径问题+长链剖分/点分治)
题面 Bzoj 洛谷 题解 首先把最短路径树建出来(用\(Dijkstra\),没试过\(SPFA\)\(\leftarrow\)它死了),然后问题就变成了一个关于深度的问题,可以用长链剖分做,所以我 ...
- Compass用法
一.什么是Compass? Compass是Sass的工具库,Compass在SASS的基础上,封装了一系列有用的模块去补充Sass的功能,类似Javascript和jQuery 二.安装 之前已经写 ...