bzoj 3916: friends 瞎搞
题目:
有三个好朋友喜欢在一起玩游戏,A君写下一个字符串S,B君将其复制一遍得到T,C君在T的任意位置(包括首尾)插入一个字符得到U.现在你得到了U,请你找出S.
题解:
发现字符串的长度一定为奇数.
然后发现问题变成了
\(s[0 .. mid]\)与\(s[mid+1 .. len]\)仅删除的编辑距离为1
或 : \(s[0 .. mid-1]\)与\(s[mid .. len]\)仅删除的编辑距离为1
然后我们可以联想到以前的:电子词典嘛
所以我们这道题可以直接暴力dfs查找..
不要忘记特判下标不同但本质相同的字符串.
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
const int maxn = 2000010;
char s[maxn];int ans,n,pos,del;
bool end_all1,end_all2;
void dfs1(int i,int j,bool f,int d){
if(end_all1) return;
if(i == pos+1){
del = d;
end_all1 = true;
++ ans;
return;
}
if(s[i] != s[j] || j == n){
if(f) dfs1(i+1,j,false,i);
else return;
}else{
dfs1(i+1,j+1,f,d);
if(f) dfs1(i+1,j,false,i);
}
}
void dfs2(int i,int j,bool f,int d){
if(end_all2) return;
if(i == n){
del = d;
end_all2 = true;
++ ans;
return;
}
if(s[i] != s[j] || j == pos){
if(f) dfs2(i+1,j,false,i);
else return;
}else{
dfs2(i+1,j+1,f,d);
if(f && i != pos) dfs2(i+1,j,false,i);
}
}
int main(){
read(n);
if(n % 2 == 0 || n == 1) return puts("NOT POSSIBLE");
pos = (n>>1);scanf("%s",s);
dfs1(0,pos+1,true,0);
if(s[pos] == s[0]) dfs2(pos+1,1,true,0);
if(ans == 2){
int i;
for(i=0;i<pos && s[i] == s[pos+i+1];++i);
if(i < pos) puts("NOT UNIQUE");
else for(int i=0;i<pos;++i) putchar(s[i]);
}
else if(ans == 0) puts("NOT POSSIBLE");
else{
if(del < pos){
for(int i=0;i<=pos;++i){
if(del == i) continue;
putchar(s[i]);
}
}else{
for(int i=pos;i<n;++i){
if(del == i) continue;
putchar(s[i]);
}
}
puts("");
}
getchar();getchar();
return 0;
}
bzoj 3916: friends 瞎搞的更多相关文章
- BZOJ 4236: JOIOJI map瞎搞
分别记录J,O,I,的个数 cnt[char][i] 表示处理到第i位,char的个数 显然当且仅当 cnt[J][i] - cnt[O][i] == cnt[J][j-1] - cnt[O][j-1 ...
- URAL 1203. Scientific Conference(瞎搞)
题目链接 本来觉得这不是经典的贪心吗..果断水一次,wa了,看了看discuss,发现貌似不好水,土土的DP了一下,复杂度很高了,又T了...然后想想单调队列,二分什么的...不好往上加,直接搞了标记 ...
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
- B. Salty Fish Go! -期望题(瞎搞题)
链接:https://www.nowcoder.com/acm/contest/104/B来源:牛客网 题意:A few days ago, WRD was playing a small game ...
- HDU5532 Almost Sorted Array(最长上升子序列 or 瞎搞个做差的数组)
题目链接:点我 题意:给定一个序列,询问是否能删除一个数让它成为非递减或者非递增的序列. 比如说 删除后的序列是1 3 3 5 或者5 3 3 1 或者1 3 5 或者5 3 1 都可以.只要满足删掉 ...
- TOJ3097: 单词后缀 (字典树 or map瞎搞)
传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...
- 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞
B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...
- ubuntu--基础环境瞎搞集合
安装ubuntu系统后有很多东西需要自己瞎搞一下,这里把一些瞎搞的过程记录在这里,方便以后重新装系统后重新配置. 一.安装. 可以在windows下制作启动盘(软碟通),然后开机u盘启动即可安装,预留 ...
- Codeforces631C【栈维护+瞎搞】
题意: 百度. 思路: 如果该查询的R比前面的所有都大,那么前面所有都失效. 那么我先预处理出这些有效的. 那最坏的情况不就是栈里面元素(R)很多 n,n-1,n-2,n-3,n-4而且都是相反排序的 ...
随机推荐
- obj-c学习笔记
本文转载至 http://blog.csdn.net/c395565746c/article/details/7573793 当对象经过在dealloc方法处理时,该对象就已经处于已销毁状态,其它 ...
- 你须知道的30个CSS选择器 »
你也许已经掌握了id.class.后台选择器这些基本的css选择器.但这远远不是css的全部.下面向大家系统的解析css中30个最常用的选择器,包括我们最头痛的浏览器兼容性问题.掌握了它们,才能真正领 ...
- lua例子getglobal()
#include <stdio.h> #define MAX_COLOR 255 extern "C" { #include "lua-5.2.2/src/l ...
- Python 字符串拼接、格式化输出、深浅复制
拼接:"+"号(同类型可拼接) >>>li = [1,2] >>>li + li [1,2,1,2] >>>li*2 [1,2 ...
- python-安装 pip
https://pip.pypa.io/en/stable/installing/ wget https://bootstrap.pypa.io/get-pip.py python get-pip.p ...
- RZ11 系统配置参数
SAP系统配置参数详解[转] SAP 系统参数设置 path: /usr/sap/PRD/SYS/profile profile: PRD_DVEBMGS00_sapapp 如果您想查看所有的参数及当 ...
- PAT 天梯赛 L2-010. 排座位 【并查集】
题目链接 https://www.patest.cn/contests/gplt/L2-010 思路 因为 题意中 朋友的朋友 就是朋友 那么 朋友的关系 用 并查集 保存 但是 敌对关系 只有直接的 ...
- c++之helloworld与命名空间
首先在linux中需要安装g++编译器. 在中端输入 uname -a,可以查看版本信息. 输入g++,如果提示错误.则需要使用sudo apt-get install g++. #include&l ...
- Data Structure Array: Find the minimum distance between two numbers
http://www.geeksforgeeks.org/find-the-minimum-distance-between-two-numbers/ #include <iostream> ...
- 【leetcode刷题笔记】Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 解题:设定一个变量 ...