HDU 4886 TIANKENG’s restaurant(Ⅱ) hash+dfs
来源:互联网 发布:中银淘宝校园卡申请 编辑:程序博客网 时间:2024/06/15 19:04
题意:
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;}
0 0
- HDU 4886 TIANKENG’s restaurant(Ⅱ) hash+dfs
- HDU 4886 TIANKENG’s restaurant(Ⅱ) (暴力+Hash)
- hdu 4886 TIANKENG’s restaurant(Ⅱ) (hash)
- HDU 4886 TIANKENG’s restaurant(Ⅱ)【hash+暴力】
- hdu 4886 TIANKENG’s restaurant(Ⅱ) 字符串
- HDU 4886 TIANKENG’s restaurant(Ⅱ)
- hdu 4886 TIANKENG’s restaurant(2)(hash+暴力)
- hdu TIANKENG’s restaurant
- TIANKENG’s restaurant HDU
- HDU 4886 TIANKENG’s restaurant(Ⅱ) (哈希)
- HDU 4886 TIANKENG’s restaurant(Ⅱ) (枚举 哈希)
- HDU 4886 TIANKENG’s restaurant(Ⅱ) 思维+字符串哈希
- TIANKENG’s restaurant(Ⅱ) hdu 4886 思维暴力
- HDU 4883 TIANKENG’s restaurant
- hdu 4883 TIANKENG’s restaurant
- HDU 4883 TIANKENG’s restaurant
- hdu 4883 TIANKENG’s restaurant
- hdu 4883 TIANKENG’s restaurant
- 12.4 Best Time to Buy and Sell Stock II
- Shell中read的选项及用法
- 网络中的TTL
- Android layoutinflater inflate()方法
- vc++抓取系统用户名
- HDU 4886 TIANKENG’s restaurant(Ⅱ) hash+dfs
- Linux分区注意点
- com.genuitec.runtime.generic.jee60 is not defined
- apache 403错误 显示如下: You don't have permission to access / on this server. 解决办法
- 临界区,互斥量,信号量,事件的区别(线程同步)
- placeholder和json两种实现登录隐藏的方法
- freemaker的语法问题
- Ultra-QuickSort(树状数组 + 离散化)
- 文件工具