【2019南京赛】

hello 2019;题意:

给出区间,要你在查询区间内有9102,同时没有8012的序列,需要删除多少个数字。

多次询问,所以给上我们的线段树。

这道题有原题;

我们dp表示i从状态i到状态j的操作次数,

我们定义0,1,2,3,4为"",2,20,201,2017的状态。对于每个状态用矩阵表示:

如dp【1】【2】从状态为2到20;

例如我们看其中一个地方{

if(s[l]==‘2‘) p[cur].a[0][0]=1,p[cur].a[0][1]=0;

表示此刻遇到了2,那么就0状态的“”到“”,要花费1

为什么呢,也就是我们“”遇到2,应变为2,但是你想保持“",那么就得删掉2,其他同理,

然后就来到但是到6的时候,保持201到201需要删除6,花费价值为1。因为不能出现2016,所以从2017转移也需要删除一个价值。

}

代码给上:

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;

const int maxx=2e5+100;
struct node{
int a[5][5];
node operator+(const node &b)const//重载加法
{
node c;
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
c.a[i][j]=inf;
for(int k=0;k<5;k++)
c.a[i][j]=min(c.a[i][j],a[i][k]+b.a[k][j]);
}
}
return c;
}
}p[maxx<<2];
char s[maxx];
int n,m;

inline void pushup(int cur)
{
p[cur]=p[cur<<1]+p[cur<<1|1];
}
inline void build(int l,int r,int cur)
{
if(l==r)
{
for(int i=0;i<5;i++)for(int j=0;j<5;j++) p[cur].a[i][j]=(i==j)?0:inf;
if(s[l]==‘2‘) p[cur].a[0][0]=1,p[cur].a[0][1]=0;
else if(s[l]==‘0‘) p[cur].a[1][1]=1,p[cur].a[1][2]=0;
else if(s[l]==‘1‘) p[cur].a[2][2]=1,p[cur].a[2][3]=0;
else if(s[l]==‘7‘) p[cur].a[3][3]=1,p[cur].a[3][4]=0;
else if(s[l]==‘6‘) p[cur].a[3][3]=1,p[cur].a[4][4]=1;
return ;
}
int mid=l+r>>1;
build(l,mid,cur<<1);
build(mid+1,r,cur<<1|1);
pushup(cur);
}
inline node query(int L,int R,int l,int r,int cur)
{
if(l<=L&&R<=r) return p[cur];
int mid=L+R>>1;
if(r<=mid) return query(L,mid,l,r,cur<<1);
else if(l>mid) return query(mid+1,R,l,r,cur<<1|1);
else return query(L,mid,l,mid,cur<<1)+query(mid+1,R,mid+1,r,cur<<1|1);
}
int main()
{
int l,r;
while(~scanf("%d%d",&n,&m))
{
scanf("%s",s+1);
build(1,n,1);
while(m--)
{
scanf("%d%d",&l,&r);
node ans=query(1,n,l,r,1);
if(ans.a[0][4]==inf) printf("-1\n");
else printf("%d\n",ans.a[0][4]);
}
}
return 0;
}

然后2019这道题就洒洒水地将序列反转变成找2019,不要2018,所以他给出区间后,你也得反转一下再询问,

代码如下:

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;

const int maxx=2e5+100;
struct node{
int a[5][5];
node operator+(const node &b)const
{
node c;
for(int i=0;i<5;i++)
{
for(int j=0;j<5;j++)
{
c.a[i][j]=inf;
for(int k=0;k<5;k++)
c.a[i][j]=min(c.a[i][j],a[i][k]+b.a[k][j]);
}
}
return c;
}
}p[maxx<<2];
char s[maxx],ss[maxx];
int n,m;

inline void pushup(int cur)
{
p[cur]=p[cur<<1]+p[cur<<1|1];
}
inline void build(int l,int r,int cur)
{
if(l==r)
{
for(int i=0;i<5;i++)for(int j=0;j<5;j++) p[cur].a[i][j]=(i==j)?0:inf;
if(s[l]==‘2‘) p[cur].a[0][0]=1,p[cur].a[0][1]=0;
else if(s[l]==‘0‘) p[cur].a[1][1]=1,p[cur].a[1][2]=0;
else if(s[l]==‘1‘) p[cur].a[2][2]=1,p[cur].a[2][3]=0;
else if(s[l]==‘9‘) p[cur].a[3][3]=1,p[cur].a[3][4]=0;
else if(s[l]==‘8‘) p[cur].a[3][3]=1,p[cur].a[4][4]=1;
return ;
}
int mid=l+r>>1;
build(l,mid,cur<<1);
build(mid+1,r,cur<<1|1);
pushup(cur);
}
inline node query(int L,int R,int l,int r,int cur)
{
if(l<=L&&R<=r) return p[cur];
int mid=L+R>>1;
if(r<=mid) return query(L,mid,l,r,cur<<1);
else if(l>mid) return query(mid+1,R,l,r,cur<<1|1);
else return query(L,mid,l,mid,cur<<1)+query(mid+1,R,mid+1,r,cur<<1|1);
}
int main()
{
int l,r;
while(~scanf("%d%d",&n,&m))
{
scanf("%s",ss+1);
for(int i=1;i<=n;i++) s[i]=ss[n-i+1];
build(1,n,1);
while(m--)
{
scanf("%d%d",&l,&r);
node ans=query(1,n,n-r+1,n-l+1,1);
if(ans.a[0][4]==inf) printf("-1\n");
else printf("%d\n",ans.a[0][4]);
}
}
return 0;
}
//感谢大佬地博客:https://blog.csdn.net/starlet_kiss/article/details/100694910

原文地址:https://www.cnblogs.com/hgangang/p/11516056.html

时间: 2024-07-31 06:40:33

【2019南京赛】的相关文章

2019模拟赛09场解题报告

目录 2019模拟赛09场解题报告 目录la~~ 题一:瞬间移动 题二:食物订购 题三:马蹄印 题四:景观美化 2019模拟赛09场解题报告 标签(空格分隔): 解题报告 Forever_chen 2019.8.20 目录la~~ 题一:瞬间移动 [题面] 有一天,暮光闪闪突然对如何将一个整数序列a1,a2,...,an排序为一个不下降序列起了兴趣.身为一只年轻独角兽的她,只能进行一种叫做"单元转换"(unit shift)的操作.换句话说,她可以将序列的最后一个元素移动到它的起始位置

HDU6706 CCPC 2019网络赛 huntian oy 推式子+杜教筛

CCPC 2019 网络赛 HDU 6706 huntian oy 标签 奇奇怪怪的数论结论 杜教筛 前言 我的csdn和博客园是同步的,欢迎来访danzh-博客园~ 简明题意 给定n,a,b,求: \[\sum_{i=1}^n\sum_{j=1}^igcd(i^a-j^a,i^b-j^b)[gcd(i,j)=1]\%(10^9+7)\] 思路 首先有一个结论: \[gcd(i^a-j^a,i^b-j^b)=i^{gcd(a,b)}-j^{gcd(a,b)}\] 上面的结论对于i,j互质是成立的

2019南京ICPC(重现赛) F - Paper Grading

题目链接:https://nanti.jisuanke.com/t/42400 这还是去年去现场赛打的,当时菜的不行,就白给了.最近学了主席树套树状数组,感觉好强的数据结构啊.我们学长说这题挺简单,建字典树dfs序,跑cdq分治就好了(%%%).本菜鸡发现这题主席树套树状数组也能做. 题意:给你n个字符串,m个操作.操作1交换俩个字符串,操作2,给定一个字符串s,数字k, l, r, 求l ~ r与s公共前缀大于等于k的字符串的个数. 首先考虑没有修改,那么就只有操作2,设f[i]为第i个字符串

The Preliminary Contest for ICPC Asia Nanjing 2019/2019南京网络赛——题解

(施工中……) 比赛传送门:https://www.jisuanke.com/contest/3004 D. Robots(期望dp) 题意 给一个DAG,保证入度为$0$的点只有$1$,出度为$0$的点只有$n$. 现在一个机器人从$1$出发,每天都会以相同的概率前往相邻节点之一或静止不动. 每天机器人消耗的耐久等于经过的天数. 求机器人到点$n$期望消耗的耐久. 划水划的很愉快,唯一一道做出来的题.但是和题解做法不同(感觉我的方法麻烦),因此砸了3h在这题上面(正在试图读懂题解ing). 设

super_log (广义欧拉降幂)(2019南京网络赛)

题目: In Complexity theory, some functions are nearly O(1)O(1), but it is greater then O(1)O(1). For example, the complexity of a typical disjoint set is O(nα(n))O(nα(n)). Here α(n)α(n) is Inverse Ackermann Function, which growth speed is very slow. So

[欧拉降幂][2019南京网络赛B]super_log

题意:输入a,b,p,求(底数a的右上角有b-1个a) 思路: 广义欧拉定理: AC代码: #include<bits/stdc++.h> typedef long long ll; using namespace std; ll a,b,m; ll vis[1000005]; ll prime[1000005],num=0; ll phi[1000005]; void getphi(ll n=1000000){ phi[1]=1; for(ll i=2;i<=n;i++){ if(!v

2019美赛D题 人员疏散模型Python编程

Louvre_Evacuation 题目来源:2019年 美赛 D题 完整代码请见:https://github.com/izcat/Louvre_Evacuation 2019 ICM Problem D: Time to leave the Louvre 问题背景 法国发生的恐怖袭击越来越多,在许多热门目的地,亟需一个应对紧急情况的疏散计划. 你们的ICM团队正在帮助设计在法国巴黎卢浮宫的疏散计划. 总的来说,疏散的目标是让所有的人都撤离,尽快安全离开大楼. 接到疏散通知后,为了尽快清空建筑

2019省赛训练组队赛4.9周二 2017浙江省赛

A - Cooking Competition "Miss Kobayashi's Dragon Maid" is a Japanese manga series written and illustrated by Coolkyoushinja. An anime television series produced by Kyoto Animation aired in Japan between January and April 2017. In episode 8, two

2019山东省赛反省

此次比赛,我很荣幸得此机会跟着学长学姐去打铁.第一次接触这种比赛,确实感到新奇,同时也有不安,因为平时没好好做题,知之甚少,基础确实是超级不稳的.好在学长说让我们开阔一下眼界,尽力就行.比赛做出几个题我就不说了,但是补题的时候真的发现我们真的很菜,简单的题我们竟然可以耗时那么久.....emmm,,以后可得努力了 A - Calandar On a planet far away from Earth, one year is composed of 12 months, and each mo