传送门

A. Creating a Character

设读入的数据分别为 $a,b,c$

对于一种合法的分配,设分了 $x$ 给 $a$

那么有 $a+x>b+(c-x)$,整理得到 $x>(b+c-a)/2$

因为 $x \in [0,c]$ ,所以求一下区间交的大小即可,注意 (b+c-a) 可能小于 0

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
int T,a,b,c;
int main()
{
T=read();
while(T--)
{
a=read(),b=read(),c=read();
if(b+c-a<) printf("%d\n",c+);
else printf("%d\n",max(c- (b+c-a)/ ,));
}
return ;
}

A

B. Zmei Gorynich

看一眼想到了屠龙勇士

首先如果可以一刀秒了那直接秒了就行

不然设单次最大伤害为 $mx$ ,就是斩杀线,一旦血量低于 $mx$ 就不用管之后会回多少血了

否则只能慢慢磨,设 $d-h$ 最大值为 $G$,那么我们每回合就只能扣 $G$ 的血

直到低于或等于斩杀线,直接斩杀即可,当然如果 $G<=0$ 则无法取胜

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline ll read()
{
ll x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const ll INF=1e18;
ll T,n,m,mx,G;
struct dat {
ll x,y;
}d[];
int main()
{
T=read();
while(T--)
{
n=read(),m=read(); mx=-INF,G=-INF;
for(int i=;i<=n;i++)
{
d[i].x=read(),d[i].y=read();
mx=max(mx,d[i].x); G=max(G,d[i].x-d[i].y);
}
if(mx>=m) { printf("1\n"); continue; }
if(G<=) { printf("-1\n"); continue; }
printf("%lld\n",(m-mx)/G+((m-mx)%G>)+);
}
return ;
}

B

C. The Number Of Good Substrings

考虑怎样的一段会产生贡献,就是某一位 $1$ 开始往右若干位,然后往左再延伸若干个连续的 $0$

显然往右移动的位数不会大于 $\log m$ ,其中 $m$ 为串长

所以对每一个 $s[i]=1$ 暴力右移,并维护当前位置最多能左移 $t$ 个 $0$,设当前区间 $[i,i+j]$ 的值为 $now$

如果满足 $now-j-1<=t$ 则合法

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=2e5+;
int T,n,a[N];
char s[N];
int Ans;
int main()
{
T=read();
while(T--)
{
scanf("%s",s+); n=strlen(s+); Ans=;
for(int i=;i<=n;i++) a[i]=(s[i]-'');
for(int i=,t=;i<=n;i++)
{
if(!a[i]) { t++; continue; }
int now=;
for(int j=;j<&&i+j<=n;j++)
{
now=(now<<)|a[i+j];
if( now-j-<=t ) Ans++;
}
t=;
}
printf("%d\n",Ans);
}
}

C

D. Coloring Edges

脑子不好用怎么办

首先强行拓扑排序一波看看有没有环,如果没有全部输出 $1$

否则

对于边 $(a,b)$,如果 $a<b$ 染 $1$,否则 $a>b$,染 $2$

这样保证所以纯色路径经过的节点编号单调递增或递减,然后就一定没环....

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=1e4+;
int n,m,du[N];
vector <int> V[N],ans;
queue <int> Q;
int main()
{
n=read(),m=read(); int x,y;
for(int i=;i<=m;i++)
{
x=read(),y=read();
ans.push_back((x<y)+);
V[x].push_back(y); du[y]++;
}
for(int i=;i<=n;i++) if(!du[i]) Q.push(i);
while(!Q.empty())
{
int x=Q.front(); Q.pop(); int len=V[x].size();
for(int i=;i<len;i++)
{
du[V[x][i]]--;
if(!du[V[x][i]]) Q.push(V[x][i]);
}
}
bool GG=;
for(int i=;i<=n;i++) if(du[i]) { GG=; break; }
if(!GG) { printf("1\n"); for(int i=;i<=m;i++) printf("1 "); }
else
{
printf("2\n");
for(int i=;i<m;i++) printf("%d ",ans[i]);
}
printf("\n");
return ;
}

D

E. Sum Queries?

考虑怎样选最能 "不平衡",发现如果选出两个数,他们某一位都不为 $0$,那么这两个数构成的集合一定不平衡,并且如果选出的两个数他们每一位都最多只有一个不为 $0$,那么一定平衡,所以对于两个数的情况我们只要考虑存在某一位都不为 $0$ 的情况

显然选两个数某一位都不为 $0$,一定比选多个数但是某些数此位为 $0$ 更优,因为我们可以不选此位为 $0$ 的那个数,最终总和还更小

所以只要考虑选两个数的情况

发现如果存在不平衡的方案,那么只要每一位分别考虑不平衡即可,因为就算如果低位进位了影响到当前位,但是低位因为有进位所以低位一定不平衡了,统计答案的时仍然会统计到这种方案

然后就可以开 $9$ 个线段树维护每一位的情况,每一个位的线段树直接维护区间 $[l,r]$ 内此位不为 $0$ 的数的最小值和次小值

然后查询的时候每一位都查询一遍取最小即可,具体看代码咯

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=2e5+,INF=1e9+;
int n,m;
struct dat {
int m1,m2;
dat (int a=INF,int b=INF) { m1=a,m2=b; }//注意初始INF
inline dat operator + (const dat &tmp) const {
dat res=*this;
if(tmp.m1<res.m1) res.m2=res.m1,res.m1=tmp.m1;
else res.m2=min(res.m2,tmp.m1);
res.m2=min(res.m2,tmp.m2);
return res;
}
};
struct SegTree {
dat t[N<<],res;
int ql,qr,pos,val;
void ins(int o,int l,int r)
{
if(l==r) { t[o]=dat(val,INF); return; }
int mid=l+r>>;
pos<=mid ? ins(o<<,l,mid) : ins(o<<|,mid+,r);
t[o]=t[o<<]+t[o<<|];
}
void query(int o,int l,int r)
{
if(l>qr||r<ql) return;
if(l>=ql&&r<=qr) { res=res+t[o]; return; }
int mid=l+r>>;
query(o<<,l,mid); query(o<<|,mid+,r);
}
inline void Ins(int x,int y) { pos=x; val=y; ins(,,n); }
inline dat Query(int l,int r) { res=dat(INF,INF); ql=l,qr=r; query(,,n); return res; }
}T[];
int main()
{
n=read(),m=read(); int opt,a,b;
for(int i=;i<=n;i++)
{
a=read();
for(int j=,t=a;j<;j++,t/=)
if(t%) T[j].Ins(i,a);
//此处可以不用Ins(INF) 因为初始就是INF
}
for(int i=;i<=m;i++)
{
opt=read(),a=read(),b=read();
if(opt==)
{
for(int j=,t=b;j<;j++,t/=)
if(t%) T[j].Ins(a,b);
else T[j].Ins(a,INF);//注意要用INF覆盖掉原来的值
continue;
}
int ans=INF*;
for(int j=;j<;j++)
{
dat t=T[j].Query(a,b);
if(t.m2<INF) ans=min(ans,t.m1+t.m2);
}
if(ans<INF*) printf("%d\n",ans);
else printf("-1\n");
}
return ;
}

E

F. Forced Online Queries Problem

神仙题,看一眼以为动态图连通性强制在线

但是 $div2$ 肯定不会这么无聊出这种毒瘤题

$Orz\ Claris$(以下为 Claris 大神 想的)

注意到 $las$ 不是 $1$ 就是 $0$,所以把 $m$ 个操作分成 $2m$ 个操作就可以知道所有可能的操作了

然后就可以离线乱搞,分治

对于当前图 $G$,有 $n$ 点 $m$ 边,$Q$ 询问

如果 $Q=1$ 则到达边界直接暴力,否则

求出当前 $G$  的所有联通块,将 $Q$ 个询问中包含的点所在的联通块保留,其他扔了

此时最多剩下 $2Q$ 个点,设操作后的图为 $G'$

将 $G'$ 和前 $Q/2$ 个操作递归处理,然后回溯后得到前 $Q/2$ 个操作完成的图 $G''$

因为前 $Q/2$ 个操作已经完成,所以知道当前 $las$ 的值

然后再将 $G''$ 和后 $Q/2$ 个操作递归处理

这个神仙算法的复杂度 $n\log n$ (n,m 同阶反正就是这个复杂度)

代码自己参考其他神仙的吧,我是不可能会的

Educational Codeforces Round 72 (Rated for Div. 2) Solution的更多相关文章

  1. Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序

    Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] ​ 给你 ...

  2. 拓扑排序入门详解&&Educational Codeforces Round 72 (Rated for Div. 2)-----D

    https://codeforces.com/contest/1217 D:给定一个有向图,给图染色,使图中的环不只由一种颜色构成,输出每一条边的颜色 不成环的边全部用1染色 ps:最后输出需要注意, ...

  3. Educational Codeforces Round 72 (Rated for Div. 2)

    https://www.cnblogs.com/31415926535x/p/11601964.html 这场只做了前四道,,感觉学到的东西也很多,,最后两道数据结构的题没有补... A. Creat ...

  4. Educational Codeforces Round 72 (Rated for Div. 2) C题

    C. The Number Of Good Substrings Problem Description: You are given a binary string s (recall that a ...

  5. Educational Codeforces Round 72 (Rated for Div. 2) B题

    Problem Description: You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a ...

  6. Educational Codeforces Round 72 (Rated for Div. 2) A题

    Problem Description: You play your favourite game yet another time. You chose the character you didn ...

  7. Coloring Edges(有向图环染色)-- Educational Codeforces Round 72 (Rated for Div. 2)

    题意:https://codeforc.es/contest/1217/problem/D 给你一个有向图,要求一个循环里不能有相同颜色的边,问你最小要几种颜色染色,怎么染色? 思路: 如果没有环,那 ...

  8. Educational Codeforces Round 72 (Rated for Div. 2)E(线段树,思维)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;#define BUF_SIZE 100000 ...

  9. Educational Codeforces Round 72 (Rated for Div. 2)C(暴力)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[200007];int a[20 ...

随机推荐

  1. 手动安装jar包到maven仓库

    1.手动安装jar包到maven仓库 本地没有下载安装maven,但是eclipse已经集成的maven. 选中任何一个maven项目,右键/Run as/maven build... 在Goals输 ...

  2. 苹果cms怎么上传本地视频资源

    今天我们来简单分享下苹果cms怎么上传本地视频,采集资源站的资源我们已经熟知了,但是有的伙伴们想要上传自己制作或是录制的视频应该怎么操作呢?这个问题有多种方法,今天我们先简单的说2种方法. 一,上传到 ...

  3. 【Mark】博弈类题目小结(HDU,POJ,ZOJ)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小 ...

  4. NOIP2009靶形数独(暴搜)

    题目传送门 题目描述 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向Z博士请教,Z博士拿出了他最近发明 ...

  5. 阿里云OSS文件上传封装

    1.先用composer安装阿里云OSS的PHPSDK 2.配置文件里定义阿里云OSS的秘钥 3.在index控制器里的代码封装 <?php namespace app\index\contro ...

  6. ES6 字符串的解构赋值

    字符串也可以解构赋值.这是因为此时,字符串被转换成了一个类似数组的对象. const [a, b, c, d, e] = 'hello'; a // "h" b // " ...

  7. 后盾网lavarel视频项目---lavarel中间件(使用中间件拦截没登录的用户)

    后盾网lavarel视频项目---lavarel中间件(使用中间件拦截没登录的用户) 一.总结 一句话总结: 1.中间件中验证用户是否登录:if(!Auth::guard('admin')->c ...

  8. modern php笔记---php (性状)

    modern php笔记---php (性状) 一.总结 一句话总结: trait是和继承一个层次的东西 一个类use MyTrait;后,trait中的方法覆盖父类方法,当前类中的方法覆盖trait ...

  9. mysql添加字段索引失败 BLOB/TEXT column 'col2' used in key specification without a key length

    看了下该表的数据结构发现col2字段类型是text ,查询了下发现是:MySQL只能将BLOB/TEXT类型字段设置索引为BLOB/TEXT数据的钱N个字符.索引指定下col2的长度就可以了 : al ...

  10. 别把&和nohup混为一谈, 根本不是同一个东西好不好 ------ 聊聊./a.out & , nohut ./a.out , nohup ./a.out &的区别

    在第一家公司工作的时候, 我认识了&,在第二家公司工作的时候, 我认识了nohup,  这就是渊源.  随后, 我就一直糊涂用他们, 但并不懂这两个东西. 网上很多地方是乱扯, 瞎复制, 为什 ...