test20181007 wzoi
题意


分析
考场40分
错误的Manacher+dp。
用\(f(i)\)表示\(s_{1 \sim i}\)的最长偶数回文覆盖长度,在Manacher的同时用刷表法转移,每次还要对\(f(i-1)\)取\(\max\)。
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<complex>
#pragma GCC optimize ("O0")
using namespace std;
template<class T> inline T read(T&x)
{
T data=0;
int w=1;
char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
data=10*data+ch-'0',ch=getchar();
return x=data*w;
}
typedef long long ll;
const int INF=0x7fffffff;
const int MAXN=1e6+7;
int n;
char s[MAXN];
char s_new[MAXN<<1];
int p[MAXN<<1];
int Init()
{
int len=strlen(s);
s_new[0]='$';
s_new[1]='#';
int j=2;
for(int i=0;i<len;++i)
{
s_new[j++]=s[i];
s_new[j++]='#';
}
s_new[j]=0;
return j;
}
int f[MAXN];
void Manacher()
{
int len=Init();
int id,mx=0;
for(int i=1;i<len;++i)
{
if(i<mx)
p[i]=min(p[2*id-i],mx-i);
else
p[i]=1;
while(s_new[i-p[i]]==s_new[i+p[i]])
++p[i];
if(mx<i+p[i])
{
id=i;
mx=i+p[i];
}
if(i>1&&s_new[i]=='#')
{
f[i/2]=max(f[i/2],f[i/2-1]);
f[i/2+(p[i]-1)/2]=max(f[i/2+(p[i]-1)/2],f[i/2-(p[i]-1)/2]+p[i]-1);
}
}
}
/*
0011011110
*/
int main()
{
// freopen("wzoi.in","r",stdin);
// freopen("wzoi.out","w",stdout);
scanf("%s",s);
n=strlen(s);
Manacher();
printf("%d\n",f[n]/2*10+(n-f[n])/2*5);
// fclose(stdin);
// fclose(stdout);
return 0;
}
然而考虑这组数据:
0011011110
\(f\)算出来:
0,2,2,2,4,4,6,6,8,8
更新没有覆盖整个偶数回文区间,导致出错。
要改的话要区间复杂的操作,无论是否有数据结构可行时间都不允许了。
好歹还有40分。
标解

单调栈+贪心解决问题。
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<complex>
#pragma GCC optimize ("O0")
using namespace std;
template<class T> inline T read(T&x)
{
T data=0;
int w=1;
char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
data=10*data+ch-'0',ch=getchar();
return x=data*w;
}
typedef long long ll;
const int INF=0x7fffffff;
int main()
{
freopen("wzoi.in","r",stdin);
freopen("wzoi.out","w",stdout);
string a,b;
cin>>a;
for(auto c:a)
{
if(b.empty()||b.back()!=c)
b.push_back(c);
else
b.pop_back();
}
printf("%d\n",5*(a.size()-b.size()/2));
// fclose(stdin);
// fclose(stdout);
return 0;
}
test20181007 wzoi的更多相关文章
- wzoi(栈模拟)
链接:https://ac.nowcoder.com/acm/contest/332/I 来源:牛客网 题目描述 bleaves 最近在 wzoi 上面做题. wzoi 的题目有两种,一种是 noip ...
- 小胖办证 wzoi
小胖办证 题目描述: xuzhenyi要办个签证.办证处是一座M层的大楼,1<=M<=100. 每层楼都有N个办公室,编号为1..N(1<=N<=500).每个办公室有一个签证 ...
- weapon制作武器
weapon制作武器 (weapon.pas/c/cpp) 解题报告 制作武器weapon.pas/c/cpp) 背景 WZland的紧急避难所很快就建好了,WZland的居民们陆续地来到这个紧急避难 ...
- Noip2013之路
当我回望过去的一年,我想,我对自己没有任何的愧疚,因为我每一个脚印,都踩的很坚实. 第一次参加模拟赛,第一次接触NOIP的规则,虽然考得不是特别好,但是还是很有收获的,首先,数组一定要开得足够大,不然 ...
- 夜未央Test1
积木游戏(block.pas) [题目描述] 春春幼儿园举办了一年一度的“积木大赛”.今年比赛的内容是搭建一座宽度为n的大厦,最高的积木的最终需要达到h. 在搭建开始之前,没有任何积木(可以看成n ...
- 10.07 WZZX Day2总结
今天仍然是KCZ出题.今天才知道KCZ不仅是WZ地区史上最强选手而且还是ZJ队长?在ZJOI拿到Rank1的男人?%%%%% 今天KCZ出题的依然很强势…… T1.wzoi 期望得分20-100 实际 ...
- NOIp2018集训test-10-6/test-10-7 (联考五day1/day2)
昨天考完月考,明天初赛,dcoi2017级今天终于开始停课准备noip了,大概没有比本弱校停课更晚的学校了吧.本来就够菜了,怕是要凉透哦. DAY1 T1石头剪刀布 据说爆搜随便做,但是我觉得我的O( ...
随机推荐
- SpringBoot+Mybatis-Generator自动生成
原文链接 1.版本 Spring Boot 1.5.10 mybatis-generator-core 1.3.5 mybatis-generator-maven-plugin 1.3.5 2.项目目 ...
- Ubuntu安装NVIDA显卡驱动
0. 综述 电脑型号:R720 Ubuntu版本:16 显卡型号:1050ti 目前,知道3种安装N卡驱动的方法: 1. PPA源:最简便,但未必有最新驱动(亲测),或可能遇到问题(风闻). sudo ...
- 使用Jenkins实现maven项目一键部署
下面的博客请详细的,值得一看:jenkins+maven+svn实现简单的一键发布 http://blog.csdn.net/pein_zero/article/details/52597615#co ...
- IP分类
IP: IP分为公有ip和私有ip. 私有ip分为以下5类: 类别 ip范围 子网掩码 A 1.0.0.0------127.255.255.255 255.0.0.0 B 128.0.0.0---1 ...
- PHP:第一章——PHP中逻辑运算符的使用方法
//逻辑运算符 $a=;$b=;$c=;$d=; //逻辑与(and 和 &&)他们两个的逻辑是一样的,如果两个值都为true,结果才为true,否则是false. //var_dum ...
- 快速切题 sgu116. Index of super-prime bfs+树思想
116. Index of super-prime time limit per test: 0.25 sec. memory limit per test: 4096 KB Let P1, P2, ...
- Flash Player离线安装包下载指南
在机房里装软件,没网是正常现象,有些老师要装Firefox/Chrome浏览器要有Flash,网上搜来搜去都是在线安装包一日在V2EX闲逛时发现了一位大神给出了Flash的离线安装包下载方式,在此立个 ...
- Linux内核分析-使用gdb跟踪调试内核从start_kernel到init进程启动
姓名:江军 ID:fuchen1994 实验日期:2016.3.13 实验指导 使用实验楼的虚拟机打开shell cd LinuxKernel/ qemu -kernel linux-3.18.6/a ...
- 第三视角团队:"Jarvis For Chat"团队选题报告
"Jarvis For Chat"团队选题报告 组长博客链接 本次作业链接 NABCD在项目中的使用 N(Need,需求) QQ和微信已经成为人们社交的必需品,在QQ有7.8亿活跃 ...
- 201621123010《Java程序设计》第12周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多流与文件相关内容. 2. 面向系统综合设计-图书馆管理系统或购物车 使用流与文件改造你的图书馆管理系统或购物车. 2.1 简述如何 ...