Codeforces Round #407 (Div. 2)

A 模拟

B 大力分类讨论

  1. |b1| > l — answer is 0.
  2. b1 = 0 — if 0 is present in array a than answer is 0, else inf.
  3. q = 1 — if b1 is present in array a than answer is 0, else inf.
  4. q =  - 1 — if both b1 and  - b1 are present in array a than answer is 0, otherwise inf.
  5. q = 0 — if 0 isn't present in array a than answer is inf, else if b1 is present in a than answer is 0, else answer is 1.
  6. 直接暴力判

或者是取巧的方法,观察到如果可能出现循环,由于循环节<=2,答案只能是0,1,inf.

//其实也要讨论,只不过代码变短了许多

C 枚举结尾的位置,类dp一波 //f[i] = 以i为头的子串最大权值

D 欧拉路径

首先,所有选2次的边不要管,只考虑走1次的2条边。

由于要满足欧拉路径的性质,大力分类一波。(共点的两条边或有自环)

细节:求Euler前应先判断图的连通性,但是图联通不一定需要所有点出现

eg.4点,3边,1--2,2--4,4--1,依然是连通图

E 将所有数-n,要求选若干数使sum=0。

以总和作为顶点,依据浓度连边(k -- ai+k),建图(2001个点,每个点最多1001条边),从点0开始bfs。

Why?  由于0 ≤ ai ≤ 1000,|总和|>1000显然无意义(因为接下来至少需要2个数来使它=0,不如早放)

//相当于找一个0到0的最小的环

另有dp方法,bfs相当于建出一张状态图

dp:一层一层来(每一层即一步),每层所有的点有2进制表示,使用bitset加速维护,对于每一条边,即将该2进制数左移a[i](或右移)。

速度慢在了无用的0,但是因为有bitset,所以不会特别慢。

原文地址:https://www.cnblogs.com/supy/p/6898089.html