首页 > 其他分享 >Codeforces Round 986 (Div. 2) CF2028 代码集

Codeforces Round 986 (Div. 2) CF2028 代码集

时间:2025-01-08 20:44:59浏览次数:1  
标签:pre CF2028 cin int 986 Codeforces Adventures Alice len

Codeforces Round 986 (Div. 2) CF2028 代码集

目录

CF2028A - Alice's Adventures in ''Chess''

int n, a, b;
string s;
void solve() {
	cin >> n >> a >> b;
	cin >> s; s = ' ' + s;
	int x = 0, y = 0;
	REP(_, 100) {
		FOR(i, 1, n) {
			if(x == a && y == b) {
				cout << "YES" << endl;
				return;
			}
			if(s[i] == 'W') x --;
			if(s[i] == 'E') x ++;
			if(s[i] == 'N') y ++;
			if(s[i] == 'S') y --;
		}
	}
	cout << "NO" << endl;
}

CF2028B - Alice's Adventures in Permuting

ll n, b, c;
void solve() {
	cin >> n >> b >> c;
	if(! b) {
		if(c <= n - 3) {
			cout << - 1 << endl;
		}
		else {
			cout << (c < n ? n - 1 : n) << endl;
		}
		return;
	}
	ll res = n;
	if(c < n) {
		res -= (n - 1 - c) / b + 1;
	}
	cout << res << endl;
}

CF2028C - Alice's Adventures in Cutting Cake

const int N = 2e5 + 5;
int n, m;
ll v, a[N], s[N];
int f[N], g[N];
void solve() {
	cin >> n >> m >> v;
	FOR(i, 1, n) cin >> a[i];
	FOR(i, 1, n) s[i] = s[i - 1] + a[i];
	FOR(i, 1, m) {
		int p = f[i - 1];
		while(p <= n && s[p] - s[f[i - 1]] < v) p ++;
		if(p > n) {
			cout << - 1 << endl;
			return;
		}
		f[i] = p;
	}
	g[0] = n + 1;
	FOR(i, 1, m) {
		int p = g[i - 1];
		while(p >= 1 && s[g[i - 1] - 1] - s[p - 1] < v) p --;
		g[i] = p;
	}
	ll ans = 0;
	FOR(i, 0, m) chmax(ans, s[g[i] - 1] - s[f[m - i]]);
	cout << ans << endl;
}

CF2024D - Alice's Adventures in Cards

const int N = 2e5 + 5;
int n, a[N], b[N], c[N];
PII pre[N];
set<PII> S1, S2, S3;
void add(int i) {
	S1.insert({a[i], i});
	S2.insert({b[i], i});
	S3.insert({c[i], i});
}
void solve() {
	cin >> n;
	FOR(i, 1, n) cin >> a[i];
	FOR(i, 1, n) cin >> b[i];
	FOR(i, 1, n) cin >> c[i];
	S1.clear(); S2.clear(); S3.clear();
	pre[n] = {0, 0};
	add(1);
	FOR(i, 2, n) {
		auto h = * S1.rbegin();
		if(FI(h) > a[i]) {
			pre[i] = {SE(h), 1};
			add(i);
			continue;
		}
		h = * S2.rbegin();
		if(FI(h) > b[i]) {
			pre[i] = {SE(h), 2};
			add(i);
			continue;
		}
		h = * S3.rbegin();
		if(FI(h) > c[i]) {
			pre[i] = {SE(h), 3};
			add(i);
			continue;
		}
	}
	if(! FI(pre[n])) {
		cout << "NO" << endl;
		return;
	}
	vector<pair<char, int>> ans;
	int u = n;
	while(u != 1) {
		if(SE(pre[u]) == 1) ans.push_back({'q', u});
		if(SE(pre[u]) == 2) ans.push_back({'k', u});
		if(SE(pre[u]) == 3) ans.push_back({'j', u});
		u = FI(pre[u]);
	}
	reverse(ans.begin(), ans.end());
	cout << "YES" << endl;
	cout << SZ(ans) << endl;
	for(auto h : ans) cout << FI(h) << " " << SE(h) << endl;
}

CF2024E - Alice's Adventures in the Rabbit Hole

const int N = 2e5 + 5;
const int P = 998244353;
const int INF = 1e9 + 7;
typedef Modint<P> mint;
int n;
int fi[N], ne[N << 1], to[N << 1], ecnt;
int d[N], son[N];
mint f[N], g[N], ans[N];
void add(int u, int v) {
	ne[++ ecnt] = fi[u];
	to[ecnt] = v;
	fi[u] = ecnt;
}
void dfs1(int u, int fa) {
	son[u] = - 1;
	for(int i = fi[u]; i; i = ne[i]) {
		int v = to[i];
		if(v == fa) continue;
		dfs1(v, u);
		if(son[u] == - 1 || d[v] < d[son[u]]) son[u] = v;
	}
	if(son[u] == - 1) {
		d[u] = 0;
		f[u] = g[u] = 0;
	}
	else if(u != 1) {
		int v = son[u];
		d[u] = d[v] + 1;
		mint x = mint(1) - f[v] / 2;
		f[u] = mint(1) / 2;
		g[u] = g[v] / 2;
		f[u] /= x, g[u] /= x;
	}
}
void dfs2(int u, int fa) {
	for(int i = fi[u]; i; i = ne[i]) {
		int v = to[i];
		if(v == fa) continue;
		ans[v] = f[v] * ans[u] + g[v];
		dfs2(v, u);	
	}
}
void solve() {
	cin >> n;
	FOR(i, 1, n) fi[i] = 0; ecnt = 0;
	REP(_, n - 1) {
		int u, v;
		cin >> u >> v;
		add(u, v);
		add(v, u);
	}
	dfs1(1, 0);
	ans[1] = 1;
	dfs2(1, 0);
	FOR(i, 1, n) cout << ans[i] << " "; cout << endl;
}

CF2024F - Alice's Adventures in Addition

const int N = 2e5 + 5;
const int M = 1e4 + 5;
const int V = 1e2 + 5;
int n, m, a[N], p[N], len;
PII b[N];
bitset<M> S, T, A, B[V];
void solve() {
	cin >> n >> m;
	FOR(i, 1, n) cin >> a[i];
	len = 0;
	FOR(i, 1, n) {
		if(a[i] == 1 && FI(b[len]) == 1) SE(b[len]) ++;
		else b[++ len] = {a[i], 1}; 
	}
	if(FI(b[len]) == 1 && SE(b[len]) > 1) {
		SE(b[len]) --;
		b[++ len] = {1, 1};
	}
	FOR(i, 0, len) p[i] = i % V;
	S.reset(); T.reset(); B[p[0]].reset();
	B[p[0]][0] = 1; T[0] = 1;
	FOR(i, 1, len) {
		if(FI(b[i]) == 0) S = T;
		B[p[i]].reset();
		B[p[i]] |= S;
		int res = 1;
		ROF(j, i, 1) {
			res *= FI(b[j]);
			if(res >= M) break;
			B[p[i]] |= B[p[j - 1]] << res;
			if(res == 0) break;
		}
		if(FI(b[i]) == 1) {
			A = B[p[i]];
			FOR(j, 1, SE(b[i]) - 1)
				B[p[i]] |= A << j;
		}
		T |= B[p[i]];
	}
	cout << (B[p[len]][m] ? "YES" : "NO") << endl;
}

标签:pre,CF2028,cin,int,986,Codeforces,Adventures,Alice,len
From: https://www.cnblogs.com/kevinlikescoding/p/18660500

相关文章

  • 基于 GEE Landsat C02 数据集合成 1986-2023 年的逐年年均 NDVI、多年均值、多年均值
    目录1完整代码2运行结果1完整代码//感兴趣的区域信息varroi=ee.FeatureCollection('projects/ee-zhangkanghnust/assets/HengShaoLou');Map.centerObject(roi);Map.addLayer(roi,{'color':'grey'},'roi');//Appliesscalingfactors.......
  • 蓝桥19865 线性规划
    太久没碰这种数学了,写的比较笨数列前k项≤2N的情况进行线性规划,约束条件有a+(k-1)d≤2n,a+kd>2n,前k项求和>2n在k≥3时,约束条件2包含约束条件3,a+(k-1)d≤2n,a+kd>2n,在[3,inf)上区域求和,就是a+2d≤2nk=1,2为特殊情况,k=1时无法满足,k=2时约束条件......
  • Codeforces 319B Psychos in a Line 题解 [ 绿 ] [ 单调栈 ] [ 动态规划 ] [ adhoc ]
    PsychosinaLine:很好的单调栈优化dp题!观察我们先观察,一个精神病人会一直杀到什么时候。显然,会杀到右边第一个比他大的精神病人那里,然后他就杀不动了。因此我们可以从右往左考虑,算出左边的精神病人杀掉这个精神病人后左边的人的答案是什么。假设左边的人目前已经刀了\(x\)......
  • (免费源码)计算机毕业设计必学必看 万套实战教程 java、python、php、node.js、c#、APP
     摘 要随着我国经济迅速发展,人们对医疗管理的需求越来越大,各种医疗管理系统也都在被广泛应用,对于医疗管理的各种软件也是备受用户的喜爱,医疗管理系统被用户普遍使用,为方便用户能够可以随时进行医疗管理系统的数据信息管理,特开发了基于springboot医疗管理系统。医疗管理系......
  • Educational Codeforces Round 166
    Dashboard-EducationalCodeforcesRound166Problem-A-Codeforces签到(写的有点烦...)#include<bits/stdc++.h>usingnamespacestd;constintN=2e5+10;voidsolve(){ intn;cin>>n; strings;cin>>s; vector<int>a;vector<char>b;......
  • Educational Codeforces Round 165
    EducationalCodeforcesRound165Problem-A-Codeforces答案只会是2或3,分类一下就好了#include<bits/stdc++.h>usingnamespacestd;constintN=2e5+10;intn;inta[N];voidsolve(){ cin>>n; for(inti=1;i<=n;i++) { scanf("%d",&a[i]......
  • Codeforces Round 993 (Div. 4)
    Codeforces题解-[题目名称]题目链接题目描述Wave获得了五个整数$k$、$l_1$、$r_1$、$l_2$和$r_2$。Wave希望你帮助她计算出有序对$(x,y)$的数量,使得以下所有条件都得到满足:$l_1\leqx\leqr_1$。$l_2\leqy\leqr_2$。存在一个非负整数$n$使得......
  • Educational Codeforces Round 172 (Rated for Div. 2)(C-D)
    题目链接:Dashboard-EducationalCodeforcesRound172(RatedforDiv.2)-CodeforcesC.CompetitiveFishingtag:后缀和+思维Description:有一个序列含\(n\)个数(每个数是\(0\)或\(-1\)),将其分为\(m\)个区间,从前往后每个区间中第\(i\)个区间的权值为\((i-1)\),求序列权值和......
  • Educational Codeforces Round 173 B.Digits
    Codeforces题解-[EducationalCodeforcesRound173B.Digits]题目链接题目大意n!个d组成的形如dd'''d(n!个)求能被1-9中哪些奇数整除每个用例按升序输出输入3267185输出13137913579解题思路解法1  这个数可以看作C=d*1111'''1(n......
  • Educational Codeforces Round 173 (Rated for Div. 2) E
    CF2043E题意给定两个\(n\timesm\)的矩阵\(A\)和\(B\)(其中的整数介于\(0\)和\(10^9\)之间),可以对\(A\)矩阵进行如下操作,问是否能变换为矩阵\(B\)。\(\&=\):选择两个整数\(i\)和\(x\(1\leqi\leqn,x\geq0)\),并将第\(i\)行中的每个元素替换为\(x\)与该......