B. hxc写的

  AC code:

#pragma GCC optimize(2)
#include <cstdio>
#include <queue>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <fstream>
#include <cassert>
#define ll long long
#define R register int
#define I inline void
#define lc c[x][0]
#define rc c[x][1] using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e6 + ;
int n,q; inline int read()
{
int x=,f=; char ch=;
while(!isdigit(ch)) {f|=ch=='-';ch=getchar();}
while(isdigit(ch)) x=(x<<)+(x<<)+(ch^),ch=getchar();
return f?-x:x;
} struct node
{
int num;
int typ;
int key;
int ans;
}pp[maxn]; vector<int> v; int getid(int x)
{
return lower_bound(v.begin(),v.end(),x) - v.begin();
} int con[maxn];
int nxt[maxn]; int cmp(node a,node b)
{
if(a.key != b.key)
return a.key > b.key;
return a.num < b.num;
} int cmp1(node a,node b)
{
return a.num < b.num;
} int find(int x)
{
if(x == nxt[x])
return x;
return nxt[x] = find(nxt[x]);
}
int u[maxn]; int main()
{
n = read();
q = read();
for(int i = ; i <= q; i++)
{
//pp[i].num = i;
int a,b;
a = read();
b = read();
pp[i].key = b;
pp[i].typ = a;
v.push_back(b);
}
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
int len = v.size(); //printf("len%d\n",len);
for(int i = ; i <= len; i++)
{
nxt[i] = i;
//printf("qwe%d\n",v[i - 1]);
} con[len - ] = ;
for(int i = ; i < len - ; i++)
{
if(v[i] + == v[i + ])
con[i + ] = ;
//printf("con%d\n",con[i]);
} /*for(int i = 1; i <= len; i++)
printf("%d %d\n",v[i - 1],con[i]);
printf("\n");*/ for(int i = ; i <= q; i++)
{
int key = getid(pp[i].key) + ;
//printf("key%d %d\n",pp[i].key,key);
if(pp[i].typ == )
{
if(con[key])
{
nxt[find(key)] = find(key + );
}
else
{
int temp = find(key);
//printf("qwe%d\n",find(key));
u[find(key)] = ;
//printf("qwe%d\n",find(key));
}
}
else
{
if(u[find(key)] == )
{
//printf("f%d\n",nxt[key]);
if(v[find(key) - ] + <= n)
//pp[i].ans = v[find(key)] + 1;
printf("%d\n",v[find(key) - ] + );
else
//pp[i].ans = -1;
printf("-1\n");
}
else
{
//printf("124252\n");
printf("%d\n",v[find(key) - ]);
}
}
} /*for(int i = 1; i <= q; i++)
if(pp[i].typ == 2)
{
printf("%d\n",pp[i].ans);
}*/
}

C. Buy Watermelon

  题意:将体积为w的西瓜切成两半,保证两半的重量均为偶数。

  思路:水题,题意含糊不清。

  AC code:

#include<cstdio>
#include<algorithm>
using namespace std; int w; int main(){
scanf("%d",&w);
if(w==||w%==) printf("NO\n");
else printf("YES\n");
return ;
}

D. Carnegion(kmp)

  题意:化简题意即判断是否为子串。

  思路:kmp查找子串,时间复杂度O(q*(S+T))。

  AC code:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<assert.h>
using namespace std; static int * GetNext(const char *sub)
{
int lensub = strlen(sub);
int *next = (int *)malloc(lensub*sizeof(int));
assert(next != NULL);
next[] = -;
next[] = ;
int j = ;
int k = ;
while(j+<lensub)
{
if((k==-) || (sub[k]==sub[j]))
next[++j] = ++k;
else
k = next[k];
}
return next;
} int KMP(const char *str,const char *sub,int pos)
{
assert(str!=NULL && sub!=NULL);
int lenstr = strlen(str);
int lensub = strlen(sub);
if(pos< || pos>=lenstr)
return -;
int *next = GetNext(sub);
int i = pos;
int j = ;
while(i<lenstr && j<lensub)
{
if(j==- || (str[i]==sub[j]))
i++,j++;
else
j = next[j];
}
free(next);
if(j >= lensub)
return i-j;
else
return -;
} const int maxn=1e5+;
int m,len1,len2;
char T[maxn],S[maxn]; int main(){
scanf("%s",T);
len1=strlen(T);
scanf("%d",&m);
while(m--){
scanf("%s",S);
len2=strlen(S);
if(len1>len2){
if(KMP(T,S,)>=) printf("my child!\n");
else printf("oh, child!\n");
}
else if(len1==len2){
if(strcmp(T,S)==) printf("jntm!\n");
else printf("friend!\n");
}
else{
if(KMP(S,T,)>=) printf("my teacher!\n");
else printf("senior!\n");
}
}
return ;
}

E. XKC‘s basketball(单调队列)

  题意:在长为5e5的数组中,对每一个a[i],求右边最后一个>=(a[i]+m)的下标。

  思路:lx写得。反向遍历,维护一个递增的队列,只进队不出队,如果当前a[i]<=que[end],那么不用进队,因为比a[i]大的数并且在i之后会屏蔽a[i]的作用; 当a[i]>que[end],则加入队尾。每次查询可以遍历得到que[begin]~que[end]中第一个>=a[i]+m的下标,当然也可以用二分加速。

  AC代码:

#include <iostream>
#include <cstdio>
#include <stack>
#include <map>
using namespace std; inline int read()
{
int x=,f=;
char ch = ;
while(!isdigit(ch))
{
if(ch=='-') f = -;
ch = getchar();
}
while(isdigit(ch))
{
x = x*+ch-'';
ch = getchar();
}
return x*f;
}
int n,m;
long long num[];
int ans[];
int dui[];
int ed;
int main()
{
n = read(), m = read();
for(int i=; i<=n; i++) num[i] = read();
for(int i=n; i>=; i--)
{
int you = ;
while(you<ed && num[i]+m>num[dui[you]]) you++;
if(you>=ed)
{
ans[i] = -;
if(num[i]>num[dui[ed-]])
{
dui[ed] = i;
ed++;
}
}
else
{
ans[i] = dui[you]-i-;
} }
for(int i=; i<=n; i++)
{
if(i>) putchar(' ');
printf("%d",ans[i]);
}
putchar('\n');
return ;
}

G. Colorful String(回文自动机)

  题意:求给定字串的所有回文子串的价值,字符串的价值定义为不同字符的个数。

  思路:回文自动机裸体。比赛现场学得回文自动机,用回文自动机求出所有种类的回文串的区间及其数量。然后用前缀记录计算得到所有回文子串的价值。

  AC code:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; typedef long long LL;
const int maxn=3e5+;
char s[maxn],s1[maxn];
int n,p,q,fail[maxn],cnt[maxn],len[maxn],tot,last,ch[maxn][],l[maxn],r[maxn];
int pre[maxn][],leng;
LL ans; inline int newnode(int x){
len[++tot]=x;
return tot;
} inline int getfail(int x,int n){
while(s[n-len[x]-]!=s[n]) x=fail[x];
return x;
} int main(){
scanf("%s",s+);
leng=strlen(s+);
for(int i=;i<=leng;++i)
s1[i]=s[i];
s[]=-,fail[]=,last=;
len[]=,len[]=-,tot=;
for(int i=;s[i];++i){
s[i]-='a';
p=getfail(last,i);
if(!ch[p][s[i]]){
q=newnode(len[p]+);
l[q]=i-len[q]+,r[q]=i;
fail[q]=ch[getfail(fail[p],i)][s[i]];
ch[p][s[i]]=q;
}
++cnt[last=ch[p][s[i]]];
}
for(int i=tot;i;--i)
cnt[fail[i]]+=cnt[i];
for(int i=;i<=leng;++i){
for(int j=;j<;++j)
pre[i][j]=pre[i-][j];
++pre[i][s1[i]-'a'];
}
for(int i=tot;i;--i){
int tmp=;
for(int j=;j<;++j)
if(pre[r[i]][j]-pre[l[i]-][j]>) ++tmp;
ans+=1LL*tmp*cnt[i];
}
printf("%lld\n",ans);
return ;
}

K. Center(计算几何)

  题意:给n个点的点集,求最少加入多少个点使得所有点关于某个点成中心对称。

  思路:n^2枚举所有点对的中点,找到枚举次数最多的中心点,该点就是最合适的中心点,假设其出现次数为Max,该点为tmp,那么答案为(n-2*Max+mp1[tmp]),mp1用来记录原始点集中点的数量。为了方便处理,可以将初始点×2,这样中心点一定为整数点。

  AC code:

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<map>
#include<utility>
using namespace std; typedef pair<int,int> PII;
const int maxn=;
int n,Max;
PII pt[maxn],tmp;
map<PII,int> mp1,mp2; int main(){
scanf("%d",&n);
for(int i=;i<=n;++i){
scanf("%d%d",&pt[i].first,&pt[i].second);
pt[i].first*=,pt[i].second*=;
++mp1[pt[i]];
}
for(int i=;i<=n;++i)
for(int j=i;j<=n;++j){
PII t=make_pair((pt[i].first+pt[j].first)/,(pt[i].second+pt[j].second)/);
++mp2[t];
if(mp2[t]>Max){
Max=mp2[t];
tmp=t;
}
else if(mp2[t]==Max){
if(mp1[t]<mp1[tmp])
tmp=t;
}
}
printf("%d\n",n-*Max+mp1[tmp]);
return ;
}

M. Longest subsequence(思维)

  题意:给定字符串s和t,求s中最长的子序列,且满足字典序大于t,输出子序列的长度,如果没有,输出-1。

  思路:比赛时没有思路。赛后补题。首先记录后缀,用aft[i][j]表示s[i]后面第一个j+’a‘的位置。然后对字符串t,枚举所求子序列从第j个字符开始大于t(前面j-1个字符与t保持一致)的情况,也就是找到pos右边第一个大于t[j]的下标x,从x开始全部选取,取答案最大值。注意子序列必须严格>t,前m个字符与t相同,之后再取后面的情况也可以。

  AC code:

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; const int maxn=1e6+;
const int inf=0x3f3f3f3f;
char s[maxn],t[maxn];
int n,m,ans,aft[maxn][],flag=; int main(){
scanf("%d%d",&n,&m);
scanf("%s%s",s+,t+);
for(int i=n-;i>=;--i){
for(int j=;j<;++j)
if(j==s[i+]-'a') aft[i][j]=i+;
else aft[i][j]=aft[i+][j];
}
int pos=;
for(int i=;i<=m;++i){
int tmp=t[i]-'a';
for(int j=tmp+;j<;++j)
if(aft[pos][j]) ans=max(ans,i+n-aft[pos][j]);
pos=aft[pos][tmp];
if(!pos){
flag=;
break;
}
}
if(flag&&pos!=n) ans=max(ans,m+n-pos);
if(!ans) printf("-1\n");
else printf("%d\n",ans);
return ;
}

2019icpc-徐州网络赛的更多相关文章

  1. 2019icpc徐州网络赛_I_query

    题意 给定一个序列,多次询问区间\([l,r]\)中满足\(min(a[i],a[j])==gcd(a[i],a[j])\)的数对\((i,j)\)数. 分析 其实就是求区间有倍数关系的数对数. 由于 ...

  2. 2019ICPC徐州网络赛 A.Who is better?——斐波那契博弈&&扩展中国剩余定理

    题意 有一堆石子,两个顶尖聪明的人玩游戏,先取者可以取走任意多个,但不能全取完,以后每人取的石子数不能超过上个人的两倍.石子的个数是通过模方程组给出的. 题目链接 分析 斐波那契博弈有结论:当且仅当石 ...

  3. 2019icpc徐州网络赛

    A Who is better? 题意 excrt+斐波那契博弈 分析 Java的BigInteger对象默认为null,不能直接比较. 代码 import java.math.BigInteger; ...

  4. 2018 ICPC 徐州网络赛

    2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...

  5. 线段树+单调栈+前缀和--2019icpc南昌网络赛I

    线段树+单调栈+前缀和--2019icpc南昌网络赛I Alice has a magic array. She suggests that the value of a interval is eq ...

  6. 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)

    query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...

  7. 2019ICPC南京网络赛A题 The beautiful values of the palace(三维偏序)

    2019ICPC南京网络赛A题 The beautiful values of the palace https://nanti.jisuanke.com/t/41298 Here is a squa ...

  8. ICPC 2019 徐州网络赛

    ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...

  9. [徐州网络赛]Longest subsequence

    [徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...

  10. 徐州网络赛B-BE,GE or NE【记忆化搜索】【博弈论】

    In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...

随机推荐

  1. 004_linux驱动之_class_create创建一个设备类

    (一)解析:class_create函数和class_destroy函数     创建一个类         和        删除一个类.   (二)class_create函数原型   struc ...

  2. python 关键参数和默认值

    def hello_key(greeting='hello', name='world'): print('%s, %s' % (greeting, name)) hello_key() hello_ ...

  3. 1626:【例 2】Hankson 的趣味题

    1626:[例 2]Hankson 的趣味题题解 [题目描述] Hanks 博士是 BT(Bio-Tech,生物技术)领域的知名专家,他的儿子名叫 Hankson.现在,刚刚放学回家的 Hankson ...

  4. Appium Inspector定位Webview/H5页面元素

    目录 操作步骤 Python操作该混合App代码 Appium在操作混合App或Android App的H5页面时, 常常需要定位H5页面中的元素, 传统方式是 翻墙 + 使用Chrome://ins ...

  5. pytorch 环境搭建

    https://pytorch.org/get-started/locally/ pip3 install torch torchvision

  6. 二十八、CentOS系统光盘安装、anaconda概述

    常见问题你会感觉 tftp timeout: 防火墙 time out script: 网关没有指定,在dhcpd.conf中 不能下载:vmlinuz和initrd程序和安装的系统版本不一致 内存必 ...

  7. mysql —日志记录

    日志 事务日志: transaction log 中继日志: reley log错误日志: error log 通用日志: general log 慢查询日志: slow query log 二进制日 ...

  8. electron之打包成安装程序

    1.安装electron-winstaller npm install --save-dev electron-winstaller 2.创建一个build.js var electronInstal ...

  9. 模糊C均值聚类的公式推导

    j=1...n,N个样本 i=1...c,C聚类 一.优化函数 FCM算法的数学模型其实是一个条件极值问题: 把上面的条件极值问题转化为无条件的极值问题,这个在数学分析上经常用到的一种方法就是拉格朗日 ...

  10. SQL-W3School-高级:SQL FOREIGN KEY 约束

    ylbtech-SQL-W3School-高级:SQL FOREIGN KEY 约束 1.返回顶部 1. SQL FOREIGN KEY 约束 一个表中的 FOREIGN KEY 指向另一个表中的 P ...