A - Toy Train

很显然,一个站有多少个糖,那么就要从这个点运多少次。设第i个点有\(a_i\)个糖,那么就要转\(a_i-1\)圈,然后再走一段。很显然最后一段越小越好。

然后枚举起点后,每个点的答案就是起点到他的距离加上再走的距离。然后取个max就好了。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
#define vi vector<int>
#define vit vector<int>::iterator
#define pir pair<int,int>
#define fr first
#define sc second
#define mp(x,y) make_pair(x,y)
using namespace std; inline char gc() {
// static char buf[100000],*p1,*p2;
// return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
return getchar();
} template<class T>
int read(T &ans) {
ans=0;char ch=gc();T f=1;
while(!isdigit(ch)) {
if(ch==EOF) return -1;
if(ch=='-') f=-1;
ch=gc();
}
while(isdigit(ch))
ans=ans*10+ch-'0',ch=gc();
ans*=f;return 1;
} template<class T1,class T2>
int read(T1 &a,T2 &b) {
return read(a)!=EOF&&read(b)!=EOF?2:EOF;
} template<class T1,class T2,class T3>
int read(T1 &a,T2 &b,T3 &c) {
return read(a,b)!=EOF&&read(c)!=EOF?3:EOF;
} typedef long long ll;
const int Maxn=1100000;
const ll inf=0x3f3f3f3f3f3f3f3fll; int n,m,a[Maxn],b[Maxn],x,y; signed main() {
// freopen("test.in","r",stdin);
read(n,m);
memset(b,0x3f,sizeof(b));
for(int i=1;i<=m;i++) {
read(x,y);
a[x]++;
if(y>x) qmin(b[x],y-x);
else qmin(b[x],y+n-x);
}
for(int i=1;i<=n;i++) if(!a[i]) b[i]=0;
for(int i=1;i<=n;i++) {
int ans=0;
for(int j=1;j<=n;j++) {
int temp;
if(j>=i) temp=j-i;
else temp=j+n-i;
temp+=(a[j]-1)*n+b[j];
qmax(ans,temp);
}
printf("%d ",ans);
}
return 0;
}

B - Wrong Answer

厚颜无耻地求一波赞

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
#define vi vector<int>
#define vit vector<int>::iterator
#define pir pair<int,int>
#define fr first
#define sc second
#define mp(x,y) make_pair(x,y)
using namespace std; inline char gc() {
// static char buf[100000],*p1,*p2;
// return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
return getchar();
} template<class T>
int read(T &ans) {
ans=0;char ch=gc();T f=1;
while(!isdigit(ch)) {
if(ch==EOF) return -1;
if(ch=='-') f=-1;
ch=gc();
}
while(isdigit(ch))
ans=ans*10+ch-'0',ch=gc();
ans*=f;return 1;
} template<class T1,class T2>
int read(T1 &a,T2 &b) {
return read(a)!=EOF&&read(b)!=EOF?2:EOF;
} template<class T1,class T2,class T3>
int read(T1 &a,T2 &b,T3 &c) {
return read(a,b)!=EOF&&read(c)!=EOF?3:EOF;
} typedef long long ll;
const int Maxn=1100000;
const ll inf=0x3f3f3f3f3f3f3f3fll; int k; signed main() {
// freopen("test.in","r",stdin);
read(k);
int temp=1999-k%1999;
puts("2000");
for(int i=1;i<=1998;i++) printf("0 ");
printf("%d ",-temp);
printf("%d\n",(k+temp)/1999+temp);
return 0;
}

C - Morse Code

首先,直接n方DP求每一段能代表的字符串的个数很简单,然后因为相同的子串只能统计一次答案,那么就用一颗trie树来存就好了。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
#define vi vector<int>
#define vit vector<int>::iterator
#define pir pair<int,int>
#define fr first
#define sc second
#define mp(x,y) make_pair(x,y)
using namespace std; inline char gc() {
// static char buf[100000],*p1,*p2;
// return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
return getchar();
} template<class T>
int read(T &ans) {
ans=0;char ch=gc();T f=1;
while(!isdigit(ch)) {
if(ch==EOF) return -1;
if(ch=='-') f=-1;
ch=gc();
}
while(isdigit(ch))
ans=ans*10+ch-'0',ch=gc();
ans*=f;return 1;
} template<class T1,class T2>
int read(T1 &a,T2 &b) {
return read(a)!=EOF&&read(b)!=EOF?2:EOF;
} template<class T1,class T2,class T3>
int read(T1 &a,T2 &b,T3 &c) {
return read(a,b)!=EOF&&read(c)!=EOF?3:EOF;
} typedef long long ll;
const int Maxn=11000000;
const int inf=0x3f3f3f3f;
const int mod=1000000007; int n,f[5100],a[Maxn],ans,ch[Maxn][2],cnt=1; signed main() {
// freopen("test.in","r",stdin);
read(n);
f[0]=1;
for(int i=1;i<=n;i++)
read(a[i]);
for(int i=1;i<=n;i++) {
memset(f,0,sizeof(f));
f[i+1]=1;
int now=1;
for(int j=i;j>=1;j--) {
for(int k=1;k<=3;k++) f[j]=(f[j]+f[j+k])%mod;
if(j<=i-3) {
if(!a[j]) {
if(a[j+1]) {
if(a[j+2]||!a[j+3]) f[j]=(f[j]+f[j+4])%mod;
}
else {
if(!a[j+2]||!a[j+3]) f[j]=(f[j]+f[j+4])%mod;
}
}
else
if(a[j+3]) {
if(!a[j+1]||!a[j+2]) f[j]=(f[j]+f[j+4])%mod;
}
else if(!a[j+1]||!a[j+2]) f[j]=(f[j]+f[j+4])%mod;
}
if(!ch[now][a[j]]) {
ch[now][a[j]]=++cnt;
ans=(ans+f[j])%mod;
}
now=ch[now][a[j]];
}
printf("%d\n",ans);
}
return 0;
}

D - Isolation

枚举右端点,然后把每个数字最后一次出现的位置设为1,倒数第二次出现的位置设为-1,这样,如果一个后缀和小于等于k,就可以转移。

然后进行分块,每一块记总和和后缀小于等于一个数的dp值的和即可。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
#include<cmath>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
#define vi vector<int>
#define vit vector<int>::iterator
#define pir pair<int,int>
#define fr first
#define sc second
#define mp(x,y) make_pair(x,y)
using namespace std; inline char gc() {
// static char buf[100000],*p1,*p2;
// return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
return getchar();
} template<class T>
int read(T &ans) {
ans=0;char ch=gc();T f=1;
while(!isdigit(ch)) {
if(ch==EOF) return -1;
if(ch=='-') f=-1;
ch=gc();
}
while(isdigit(ch))
ans=ans*10+ch-'0',ch=gc();
ans*=f;return 1;
} template<class T1,class T2>
int read(T1 &a,T2 &b) {
return read(a)!=EOF&&read(b)!=EOF?2:EOF;
} template<class T1,class T2,class T3>
int read(T1 &a,T2 &b,T3 &c) {
return read(a,b)!=EOF&&read(c)!=EOF?3:EOF;
} typedef long long ll;
const int Maxn=110000;
const int inf=0x3f3f3f3f;
const int mod=998244353; int bn[Maxn],bl[Maxn],br[Maxn],f[Maxn],b[Maxn],a[Maxn],in[Maxn],bf[500][1000],n,k,las[Maxn],pre[Maxn]; inline int modd(int x) {
return x>=mod?x-mod:x;
} void update(int x) {
memset(bf[x],0,sizeof(bf[0]));
bn[x]=0;
for(int i=br[x];i>=bl[x];i--) {
bf[x][bn[x]+500]=modd(bf[x][bn[x]+500]+f[i]);
bn[x]+=b[i];
}
for(int i=1;i<1000;i++) bf[x][i]=modd(bf[x][i]+bf[x][i-1]);
} signed main() {
// freopen("test.in","r",stdin);
read(n,k);
int m=sqrt(n);
memset(bl,0x3f,sizeof(bl));
memset(las,-1,sizeof(las));
memset(pre,-1,sizeof(pre));
f[0]=1;
for(int i=0;i<=n;i++) {
in[i]=i/m;
qmin(bl[in[i]],i);
qmax(br[in[i]],i);
}
update(0);
for(int i=1;i<=n;i++) {
read(a[i]);
if(~las[a[i]]) {
pre[i]=las[a[i]];
b[las[a[i]]]=-1;
update(in[las[a[i]]]);
if(~pre[las[a[i]]]) {
b[pre[las[a[i]]]]=0;
update(in[pre[las[a[i]]]]);
}
}
b[i]=1;
int now=1;
for(int j=i-1;j>=bl[in[i]];j--) {
if(now<=k) f[i]=modd(f[i]+f[j]);
now+=b[j];
}
for(int j=in[i]-1;j>=0;j--) {
if(k-now+500>0) f[i]=modd(f[i]+bf[j][min(k-now+500,999)]);
now+=bn[j];
}
update(in[i]);
las[a[i]]=i;
}
printf("%d\n",f[n]);
return 0;
}

Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1)的更多相关文章

  1. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题解

    Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) 题目链接:https://codeforces.com/contest/1130 ...

  2. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) C(二分+KMP)

    http://codeforces.com/contest/1129/problem/C #include<bits/stdc++.h> #define fi first #define ...

  3. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2) A - D2

    A. Be Positive 链接:http://codeforces.com/contest/1130/problem/A 题意: 给一段序列,这段序列每个数都除一个d(−1e3≤d≤1e3)除完后 ...

  4. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 2)

    A. Be Positive 题意:给出一个数组 每个树去除以d(d!=0)使得数组中大于0的数 大于ceil(n/2) 求任意d 思路:数据小 直接暴力就完事了 #include<bits/s ...

  5. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1)C. Morse Code

    题意:给你n个01字符,每次问你前缀的所有本质不同的子串,由摩斯密码组成的方案数和. 题解:离线处理,把字符建sam,通过topo序来dp计算每个节点表示的子串方案数的和.统计答案时,把n个字符挨个匹 ...

  6. Codeforces Round #542 [Alex Lopashev Thanks-Round] (Div. 1) 题解

    A. Toy Train 时间限制:2 seconds 内存限制:256 megabytes 题意 有编号111~n(n≤5000)n(n\le 5000)n(n≤5000)的车站顺时针呈环排列,有m ...

  7. Codeforces Round 542 (Div. 2)

    layout: post title: Codeforces Round 542 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  8. Codeforces Round #542 题解

    Codeforces Round #542 abstract I决策中的独立性, II联通块染色板子 IIIVoronoi diagram O(N^2 logN) VI环上距离分类讨论加取模,最值中的 ...

  9. int和integer;Math.round(11.5)和Math.round(-11.5)

    int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...

随机推荐

  1. mysql中的日志

    关键词:mysql日志,mysql四种日志 一.mysql日志的种类 (1)一般来说,日志有四种,分别为: 1.错误日志:log-err (记录启动,运行,停止mysql时出现的信息) 2.二进制日志 ...

  2. android发短信,打电话

    //1.进入系统短信列表界面 Intent intent = newIntent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_DEF ...

  3. react-native 相关问题

    使用create-react-native-app时,报错,好像是npm版本不对,想问下npm怎么降低版本? npm install npm@4 -g  创建并启动项目 老方法1 创建项目 react ...

  4. scipy模块

  5. Nhibernate入门与demo

    学习和使用Nhibernate已经很久了,一直想写点东西和大家一起学习使用Nhibernate.博客园里也有很多大牛写了很多关于Nhibernate入门的文章.其中:李永京的博客http://www. ...

  6. ASP.NET控件--DropDownList

      设置默认值:DropDownList1.Items[i].Selected=true;绑定:DropDownList1.DataSource = dataSet.Tables["Tabl ...

  7. Python: 猴子分桃。海滩上有一堆桃子,五只猴子来分。

    海滩上有一堆桃子,五只猴子来分.第一只猴子把这堆桃子平均分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份.第二只猴子把剩下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿走了一 ...

  8. Java 简明教程

    本文为 Java 的快速简明教程,主要用于快速了解.学习和复习java的语法特点. // 单行注释 /* 多行注释 */ /** JavaDoc(Java文档)注释是这样的.可以用来描述类和类的属性. ...

  9. python 模拟windows键盘按键的封装

    代码:在执行的时候,把光标放在指定的地方,在此例中,点击运行后把光标放到结果区域,粘贴的时候是粘贴到光标所在的问题,如过是运行脚本在web元素输入框中输入的话,不能移动光标到其他位置 #encodin ...

  10. xml之一

    xml基础知识 标记语言<> XML与HTML区别 1.HTML主要用来显示  XML是用来进行数据传输 2.HTML是一种预定义的(<a>表示超链接),xml不是预定义的(& ...