心路历程

预计得分:$30 + 0 + 0 = 30$

实际得分:$0+0+0= 0$

T1算概率的时候没模爆long long了。。。

A

我敢打赌这不是noip难度。。。

考虑算一个位置的概率,若想要$k$步把它干掉,那么与他距离为$1$到$k - 1$的点都必须阻塞

且距离为$k$的点至少有一个没被阻塞

概率的处理可以用前缀和优化。

这样看似是$O(n^3 logn)$,但是却不能通过,考虑在前缀和处理的时候有很多没用的状态(超出边界)

加一些剪枝即可

#include<cstdio>
#define max(a, b) (a < b ? b : a)
#define LL long long
using namespace std;
const int MAXN = , mod = 1e9 + , INF = 1e9 + ;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N, M, a[MAXN][MAXN], g[MAXN][MAXN][MAXN], vis[MAXN][MAXN];
LL fastpow(LL a, LL p) {
LL base = ;
while(p) {
if(p & ) base = 1ll * base * a % mod;
a = 1ll * a * a % mod; p >>= ;
}
return base;
}
LL inv(LL a) {
return fastpow(a, mod - );
}
int mul(int a, int b) {
if(1ll * a * b > mod) return 1ll * a * b % mod;
else return a * b;
}
void Pre() {
//cout << a[1][1] << endl;
for(int i = ; i <= N; i++)
for(int j = ; j <= M; j++)
g[][i][j] = a[i][j] % mod; for(int k = ; k <= max(N, M); k++)
for(int i = ; i <= N; i++)
for(int j = ; j <= M; j++) {
if((i - k < ) || (j - k < ) || (i + k > N + ) || (j + k > M + )) {vis[i][j] = ; continue;}
if(vis[i][j]) continue;
g[k][i][j] = mul(g[k - ][i - ][j], g[k - ][i + ][j]);
if(k > ) g[k][i][j] = mul(g[k][i][j], inv(g[k - ][i][j]));
if(k >= ) g[k][i][j] = mul(mul(g[k][i][j], inv(a[i][j + k - ])), inv(a[i][j - k + ]));
g[k][i][j] = mul(mul(g[k][i][j], a[i][j + k]), a[i][j - k]);
}
}
LL calc(int x, int y) {
LL ans = , s = a[x][y];
for(int i = ; i <= max(N, M); i++) {
if((x - i < ) || (y - i < ) || (x + i > N + ) || (y + i > M + )) break;
int now = g[i][x][y];
ans = (ans + mul(mul(i, ( - now + mod)), s)) % mod;
s = mul(s, now);
}
return ans;
}
int main() {
// freopen("a.in", "r", stdin);
N = read(); M = read();
for(LL i = ; i <= N; i++) {
for(LL j = ; j <= M; j++) {
LL x = read(), y = read();
a[i][j] = mul(x, inv(y));
}
}
Pre();
for(LL i = ; i <= N; i++, puts(""))
for(LL j = ; j <= M; j++)
printf("%lld ", calc(i, j) % mod);
return ;
}

A

B

考场上根本就没时间做。。

题目给出的模型太难处理了,考虑转化成一个较为普通的模型

遇到这种每个点有两个状态的题不难想到拆点,分别表示赢 / 输

当$a$赢了$b$,就从$a$赢向$b$输连边。

这样会得到一个新的无环图,可以证明,两个图中的环是等价的。

直接暴力找最小环即可,时间复杂度:$O(n^2 T)$

#include<bits/stdc++.h>
using namespace std;
const int MAXN = , BIT = ;
int N, M, dep[MAXN], fa[MAXN][], MC, U, V;
vector<int> v[MAXN];
int LCA(int x, int y) {
if(dep[x] < dep[y]) swap(x, y);
for(int i = BIT; i >= ; i--) if(dep[fa[x][i]] >= dep[y]) x = fa[x][i];
if(x == y) return x;
for(int i = BIT; i >= ; i--) if(fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
return fa[x][];
}
void bfs(int x) {
queue<int> q;
q.push(x); dep[x] = ; fa[x][] = ;
while(!q.empty()) {
int p = q.front(); q.pop();
for(int i = , to; i < v[p].size(); i++) {
if(!dep[to = v[p][i]]) {
fa[to][] = p; dep[to] = dep[p] + ;
for(int j = ; j <= BIT; j++) fa[to][j] = fa[fa[to][j - ]][j - ];
q.push(to);
}
else if(to != fa[p][]) {
int lca = LCA(p, to), dis = dep[p] + dep[to] - * dep[lca] + ;
if(dis < MC) MC = dis, U = p, V = to;
}
}
}
}
int main() {
int meiyong; scanf("%d", &meiyong);
while(scanf("%d", &N) && N) {//tag
scanf("%d", &M); MC = MAXN;
for(int i = ; i <= * N; i++) v[i].clear();
memset(dep, , sizeof(dep));
memset(fa, , sizeof(fa)); for(int i = ; i <= M; i++) {
int x, y; scanf("%d %d", &x, &y);
v[x].push_back(y + N); v[y + N].push_back(x);
} for(int i = ; i <= * N; i++) if(!dep[i]) bfs(i);
if(MC == MAXN) {puts("-1");continue;}
int lca = LCA(U, V);
vector<int> ans; ans.clear();
printf("%d\n", MC);
while(U != lca) printf("%d ", (U - ) % N + ), U = fa[U][];
printf("%d", (lca - ) % N + );
while(V != lca) ans.push_back((V - ) % N + ), V = fa[V][];
for(int i = ans.size() - ; i >= ; i--) printf(" %d", ans[i]);
puts("");
}
return ;
}
/*
*/

B

C

$k=2$的时候是斐波那契博弈

$k \not = 2$的时候是神仙结论

考虑$k \not = 2$怎么做。

结论:

若$l = n$时先手必输,那么我们找到一个$m = \frac{n}{k} >= n$,且最小的$m$,当$l = n+m$先手也一定必输

证明:

我们把多着的$m$个单独考虑,若$n < l < n+m$时,先手拿走多余的$m$个,后手必败。

但当$l = n +m$时,先手不能拿走$m$个,因为此时后手可以一步拿走剩余的。

不断往下推就行了

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 1e7 + ;
int T, k, top;
LL l, sta[MAXN];
int main() {
cin >> T;
while(T--) {
cin >> k >> l;
LL now = ;
sta[top = ] = ;
while(now < l) {
int nxt = lower_bound(sta + , sta + top + , (now % k == ) ? now / k : (now / k + )) - sta;
sta[++top] = (now = (now + sta[nxt]));
}
puts(now == l ? "DOG" : "GOD");
}
return ;
}
/*
1
2 21
*/

C

牛客NOIP提高组(三)题解的更多相关文章

  1. 牛客NOIP提高组(二)题解

    心路历程 预计得分:100 + 40 + 30 = 170 实际得分:100 + 30 + 0 = 130 T2有一个部分分的数组没开够RE了. T3好像是思路有点小问题.. 思路没问题,实现的时候一 ...

  2. 牛客NOIP提高组R1 C保护(主席树)

    题意 题目链接 Sol Orz lyq 我们可以把一支军队(u, v)拆分为两个(u, lca)和(v, lca) 考虑一个点x,什么时候军队对它有贡献,肯定是u或v在他的子树内,且lca在他的子树外 ...

  3. 牛客NOIP提高组R1 A中位数(二分)

    题意 题目链接 Sol 很神仙的题目啊,考场上只会$n^2$的暴力.. 考虑直接二分一个$mid$,我们来判断最终答案是否可能大于$x$. 判断的时候记录一下前缀最小值即可, 设$s[i]$表示$1- ...

  4. 牛客CSP-S提高组赛前集训营1

    牛客CSP-S提高组赛前集训营1 比赛链接 官方题解 before:T1观察+结论题,T2树形Dp,可以换根或up&down,T3正解妙,转化为图上问题.题目质量不错,但数据太水了~. A-仓 ...

  5. 计蒜客 NOIP 提高组模拟竞赛第一试 补记

    计蒜客 NOIP 提高组模拟竞赛第一试 补记 A. 广场车神 题目大意: 一个\(n\times m(n,m\le2000)\)的网格,初始时位于左下角的\((1,1)\)处,终点在右上角的\((n, ...

  6. 18/9/16牛客网提高组Day2

    牛客网提高组Day2 T1 方差 第一眼看就知道要打暴力啊,然而并没有想到去化简式子... 可能因为昨晚没睡好,今天上午困死 导致暴力打了一个半小时,还不对... #include <algor ...

  7. 18/9/9牛客网提高组Day1

    牛客网提高组Day1 T1 中位数 这好像是主席树??听说过,不会啊... 最后只打了个暴力,可能是n2logn? 只过了前30%  qwq #include<algorithm> #in ...

  8. 牛客网 提高组第8周 T1 染色

    染色 链接: https://ac.nowcoder.com/acm/contest/176/A 来源:牛客网 题目描述 \(\tt{fizzydavid}\)和\(\tt{leo}\)有\(n\)个 ...

  9. 牛客网 提高组第8周 T2 推箱子 解题报告

    推箱子 链接: https://ac.nowcoder.com/acm/contest/176/B 来源:牛客网 题目描述 在平面上有\(n\)个箱子,每个箱子都可以看成一个矩形,两条边都和坐标轴平行 ...

随机推荐

  1. NEKOGAMES

    http://bbs.3dmgame.com/thread-4133434-1-1.html

  2. 28、cd-hit去除冗余序列

    转载:http://blog.sina.com.cn/s/blog_670445240101nidy.html 网址:http://cd-hit.org :http://www.bioinformat ...

  3. tensorflow session会话控制

    import tensorflow as tf # create two matrixes matrix1 = tf.constant([[3,3]]) matrix2 = tf.constant([ ...

  4. Entity Framework Code-First(9.11):DataAnnotations - InverseProperty Attribute

    DataAnnotations - InverseProperty Attribute: We have seen in the Code-First Convention section that ...

  5. 电脑MAC地址

    电脑MAC地址(Media Access Control) MAC地址是固化在网卡上串行EEPROM中的物理地址,通常有48位长.用来表示互联网上每一个站点的标识符,采用十六进制数表示. 任一网络设备 ...

  6. JAVA中判断char是否是中文的几种方法

    1.方法一 char c = 'a'; if((c >= 0x4e00)&&(c <= 0x9fbb)) { System.out.println("是中文&qu ...

  7. codeforces 367B

    题目代码到是不难但是很难想通题目的解决方法. #include<iostream> using namespace std; ]; int main() { int n,m; while( ...

  8. EIP权限工作流平台总结-2前端框架

      1.预览地址:www.eipflow.com (1) 权限工作流:www.demo.eipflow.com/Account/Login (2) 基础权限版:www.auth.eipflow.com ...

  9. sql各种查询技巧

    SQL Server T-SQL高级查询 高级查询在数据库中用得是最频繁的,也是应用最广泛的. Ø 基本常用查询 --select select * from student; --all 查询所有 ...

  10. MCP|XHK|High-density peptide arrays help to identify linear immunogenic B cell epitopes in individuals naturally exposed to malaria infection(高密度肽段阵列有助于在自然暴露于疟疾感染的个体中识别线性免疫原性B细胞表位)

    文献名:High-density peptide arrays help to identify linear immunogenic B cell epitopes in individuals n ...