Educational Codeforces Round 85 (Rated for Div. 2)

Educational Codeforces Round 85 (Rated for Div. 2)

A. Level Statistics

签到题, 要求第一位维单增, 第二维变化比第一维慢, 直接模拟即可

B. Middle Class

题目大意

每个人有一些财富, 财富值超过x的人称为富人, 由于实行共产主义, 你可以将某些人的财产重新分配使得富人最多

解题思路

直接按财富值排序, 从大到小加入富人集合, 如果当前富人集合财富平均值小于x就break掉

C. Circle of Monsters

题目大意

有一圈怪物, 它们每个都有一些生命值\(a_i\), 爆炸时对第\((i\%n)+1\)个怪物造成\(b_i\)的伤害, 你每次可以打一滴血, 问最少打几次

解题思路

首先贪心的想到从一个点开始,肯定是连着打下去的, 也就是打怪顺序类似这样\(i,i+1,i+2,i+3\), 只有这样才可以利用用上每个怪物爆炸所产生的价值, 所以我们倍长, 断环成链, \(c_i=(i-1)爆炸后自己还需打的次数 = a_{i}-b_{i-1}\), 对其记一下前缀和, 枚举第一个打哪个怪物即可

const int N = 1000050;
ll a[N], b[N], sum[N], T, n;
int main() {
	read(T);
	while (T--) {
		read(n);
		for (int i = 1;i <= n; i++)
			read(a[i]), read(b[i]),
			a[i+n] = a[i], b[i+n] = b[i];
		for (int i = 1;i <= 2 * n; i++)
			sum[i] = sum[i-1] + max(a[i] - b[i-1], 0ll);
		ll ans = a[1] + sum[n] - sum[1];
		for (int i = 1;i <= n; i++)
			ans = min(a[i] + sum[i+n-1] - sum[i], ans);
		printf ("%lld\n", ans);
	}
	return 0;
}

D. Minimum Euler Cycle

题目大意

给一个完全有向图, 也就是每两个不同的点都有两条有向边, 从1点开始走, 每条边只可遍历一次, 求一种方案使遍历点序列的字典序最小\(1->2->1->3->1->4 =1 2 1 3 1 4\)

解题思路

模拟一下可以发现, 先从1点到其他节点然后立刻从其他节点回来, 但到n号节点时则不能回来因为回来就无路可走, n号节点只能走向2号节点, 2号节点在依次走向\(2,3,4...\)号节点并返回, 到n号节点时走向3号节点, 发现就是从小到大把这个点所有的连边都走尽最后到达n号节点并进入下一个点的轮回, 要注意的是最后n点要回到1点

ll T, n, l, r;
int main() {
	read(T);
	while (T--) {
		read(n), read(l), read(r);
		if (n == 2) {

		}
		ll sum = 0, pre = 0;
		for (int i = 1;i < n; i++) {
			sum += (n - i) * 2;
			if (l < sum) {
				ll t = l - pre;
				ll x = (t & 1) ? i : (t / 2) + i, y = (t / 2) + i;
				while (l < sum && l <= r) {
					printf ("%lld ", x);
					x == i ? y++, x = y : x = i;
					l++;
				}
			}
			if (l == sum && l <= r) printf ("%lld ", n), l++;
			pre = sum;
			if (l > r) break;
		}
		if (l <= r) printf ("1");
		puts("");
	}
	return 0;
}

E. Divisor Paths

题目大意

给定一个正整数D, 以此建图

  • 每个节点都是D的因子
  • 俩节点(x, y)有无向边存在的条件是y是x因子且\(\frac xy\)是质数
  • (x, y)的边权是x的因子中不是y的因子的个数

求q组\((1\le q \le 3\cdot10^5)\)(a, b)的最短路径个数

解题思路

大力猜结论题

首先发现从x和y的边权是什么呢, 设\(k=\frac xy\), 则边权为while (y % k == 0) y /= k之后y的因子个数, 更严谨的讲\(y = k^{a_1}p_1^{a_2}...p_n^{a_{n+1}}\), 在x中却不再y中只可能是\(k^{a_1+1}*X\)的形式, k要取到最高次才可以产生贡献, 可以模拟一下.

从y走到x的本质是什么呢, 就是加一个质因子进来并付出一定代价

然后两个数肯定是向上跳到它们的lcm停止, 否则肯定不优, 而且我们发现从x到lcm添加质因子的顺序不同, 路径长度是一样的, 这代表着我们只用记录从x到lcm有多少添加质因子的方法再乘上y的方案数就是答案

求解添加质因数方案数时可以用组合数转移, 当前集合方案数=之前集合方案数*C(当前集合大小, 新增质因子个数), 也可以用其他方法,不再赘述

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c==‘-‘) f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int P = 998244353;
ll d, a, b, n;
map<ll, int> mp;
ll y[500], cnt;
ll tmp[50], jie[500], inv[500];

inline ll C(ll n, ll m) {
	return jie[n] * inv[n-m] % P * inv[m] % P;
}

int main() {
	read(d), read(n); if (d % 2 == 0) y[++cnt] = 2;
	while (d % 2 == 0) d /= 2;
	for (ll i = 3;i * i <= d; i += 2) {
		if (d % i) continue;
		y[++cnt] = i;
		while (d % i == 0) d /= i;
	}
	if (d != 1) y[++cnt] = d;
	jie[0] = 1; for (int i = 1;i <= 100; i++) jie[i] = jie[i-1] * i % P;
	inv[0] = inv[1] = 1;
	for (int i = 2;i <= 100; i++) inv[i] = (P - P / i) * inv[P % i] % P;
	for (int i = 2;i <= 100; i++) inv[i] = inv[i-1] * inv[i] % P;
	while (n--) {
		read(a), read(b);
		ll aa = 0, bb = 0, s1 = 1;
		for (int i = 1;i <= cnt; i++) {
			int ta = 0, tb = 0;
			while (a % y[i] == 0) a /= y[i], ta++;
			while (b % y[i] == 0) b /= y[i], tb++;
			int tt = max(ta, tb);
			aa += tt - ta, bb += tt - tb;
			s1 = (s1 * C(aa, tt - ta) % P * C(bb, tt - tb)) % P;
		}
		printf ("%lld\n", s1 % P);
	}
	return 0;
}

原文地址:https://www.cnblogs.com/Hs-black/p/12677650.html

时间: 2024-10-07 17:10:23

Educational Codeforces Round 85 (Rated for Div. 2)的相关文章

【补题】Educational Codeforces Round 85 (Rated for Div. 2)

C题直接贪心,D题欧拉回路,理论上应该会做的-- 然后应该读题比较慢的关系,A题+B题各做了20分钟--还是15分钟内连切两道比较理想,毕竟挂了梯子,开CF的速度也不慢. C. Circle of Monsters \(n\)只怪物站成一圈,第\(i\)只怪物有\(a[i]\)点生命值和\(b[i]\)点爆炸伤害.当第\(i\)只怪物死亡时会爆炸,且只对第\(i+1\)只怪物造成\(b[i]\)点伤害.爆炸可以传递.每次开枪会对其中一只怪物造成\(1\)点伤害,求能杀死全部怪物的最小开枪次数.

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二场CF! 成绩:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 题目:Educational Codeforces Round 57 (Rated for Div. 2) 错题题解: D. Easy Problem E. The Top Scorer F. Inversion Expectation G. Lucky Tickets 原文地址:https://www.cnblogs.com/xht37/p/10198321.html

Educational Codeforces Round 58 (Rated for Div. 2)(待更新)

get人生第七场CF! 成绩:(exACM) rank AC3/7 Penalty104 rating() 题目:Educational Codeforces Round 58 (Rated for Div. 2) 错题题解: C. Division and Union 原文地址:https://www.cnblogs.com/xht37/p/10260260.html