counting atcoder another 259h

G. Counting Graphs

G. Counting Graphs 题意:添加几条线段,使得图仍保持原先的最小生成树 通过画图我们发现,要添加u->v的线段,线段必须大于u->v的路径内的最大值,不然会破坏原先的最小生成树。 那么该怎么维护路径内的最大值呢? 方法: 1.我们对边的大小进行排序,这样当前边一定大于等于之前的边,只 ......
Counting Graphs

AtCoder Grand Contest 036 F Square Constraints

洛谷传送门 AtCoder 传送门 本质是 \(p_i \in [l_i, r_i]\) 的计数问题。 当 \(1 \le i \le n\) 时,\(l_i\) 才可能不等于 \(1\)。考虑容斥,设钦定 \(m\) 个不满足条件(上界为 \(l_i - 1\)),其余任意(上界为 \(r_i\) ......
Constraints AtCoder Contest Square Grand

AtCoder Beginner Contest 288 Ex A Nameless Counting Problem

洛谷传送门 AtCoder 传送门 考虑到规定单调不降比较难搞。先设 \(g_t\) 为长度为 \(t\) 的满足条件的序列个数(可重且有顺序)。求这个可以设个 dp,\(f_{d, i}\) 表示考虑到从高到低第 \(d\) 位,当前 \(t\) 个数中有 \(i\) 个仍然顶上界,并且之前的位都 ......
Beginner Counting Nameless AtCoder Contest

Atcoder abl c

传送门 题目描述 有n个城市,m条双向路的图,问你最少添加几条路使得任意两个城市可以两两到达? 样例 样例输入 3 1 1 2 样例输出: 1 题目解析 这是个双向路的图,我们可以把它当成一个非连通图。在各个点之间有连线,要求我们算出如何能将整个图的各个部分连接起来。那么,我们只要算出这个非连通图由 ......
Atcoder abl

AtCoder——第一题

AtCoder Beginner Contest 322 F Vacation Query 题目大意 处理01字符串,给定Q次询问,询问区间内最长连续1的字符个数 题目理解 使用线段树维护区间 需要使用懒标记下传修改信号 线段树要维护7个信息(区间的最长连续1的个数、区间左端点开始连续1的个数、区间 ......
AtCoder

AtCoder Grand Contest 056 D Subset Sum Game

洛谷传送门 AtCoder 传送门 考虑若 \(n\) 是奇数怎么做。枚举 Alice 第一次选的数 \(a_i\),然后考虑把剩下的数两两结成一个匹配,若 Bob 选了其中一个,Alice 就选另一个。容易发现排序后奇数位和它右边的偶数位匹配最优。那么设奇数位的和为 \(A\),偶数位的和为 \( ......
AtCoder Contest Subset Grand Game

挑战程序设计竞赛 2.1章习题 POJ 2386 Lake Counting

https://vjudge.net/problem/POJ-2386 由于最近的降雨,水在农夫约翰的田地上聚集,在这片田地中,每个方块都被表示为一个 N x M(1 ≤ N ≤ 100;1 ≤ M ≤ 100)的矩形。 每个方块可以是水('W')或干地('.')。农夫约翰想弄清楚他的田地上形成了多 ......
习题 程序设计 Counting 程序 2386

AtCoder Beginner Contest 178 E

AtCoder Beginner Contest 178 E E - Dist Max 曼哈顿距离最大点对 \(ans = max(|x_i-x_j|+|y_i-y_j|)\) 考虑去绝对值,4种情况。sort一下取max即可。 #include <bits/stdc++.h> using name ......
Beginner AtCoder Contest 178

AtCoder Beginner Contest 322

A - First ABC 2 解题思路 签到 Code #include <bits/stdc++.h> using namespace std; typedef long long LL; void solve() { int n; cin >> n; string s; cin >> s; i ......
Beginner AtCoder Contest 322

[AtCoder] E - Packing Under Range Regulations

Key idea: For a given box and a list of balls that can be placed in this box, we should choose the ball with the smallest R. Proof: say we have box B ......
Regulations AtCoder Packing Under Range

AtCoder Beginner Contest 322

A - First ABC 2 (abc322 A) 题目大意 给定一个字符串,找到最先出现ABC的位置。 解题思路 直接查找判断即可。 神奇的代码 #include <bits/stdc++.h> using namespace std; using LL = long long; int mai ......
Beginner AtCoder Contest 322

counting题解

\(N,M\le 1e7\) 接着反射容斥,考虑这道题怎么做 如果去枚举不动步数,加上反射容斥,直接T飞了 把-1/0/1操作转换一下,就成了0/1/2 如果没有限制(不能<0或>m),n步方案就是\((1+x+x^2)^n\) 设\(H=1+x+x^2\quad F=H^n\) 那么对两边求导: ......
题解 counting

加训日记 Day3——atcoder ABC321乐子场

Day3,9.23 ·打了场acwing周赛,第三题差点就想出来了,想歪到组合数上乱选了呜呜呜 ·ABC321场写的太抽象了,A题上来wa两次,B题少考虑情况乱wa ·C题更是重量级,想不出来正确做法直接暴力,结果打表最后少写了几个数,纯纯犯病场 ·最后加了36分没绷住 acwing周赛排名 atc ......
乐子 atcoder 日记 Day3 Day

AtCoder Regular Contest 123 F Insert Addition

洛谷传送门 AtCoder 传送门 用 \((x, y)\) 表示 \(Ax + By\),那么这个等价于 SB 树。 那么直接在 SB 树上二分,遍历一遍找到 \(n\) 个点就好了。可以采用类似线段树查询的方式。 于是现在还剩下一个子问题:给定 \(a, b\),求 \(ax + by \le ......
Addition AtCoder Regular Contest Insert

AtCoder Regular Contest 127 F ±AB

洛谷传送门 AtCoder 传送门 非常妙的题。 先直观感受一下,显然当 \(M\) 大到一定程度后,\([0, M]\) 的所有数都能被取到。考虑 \(V \gets V + Ax + By\),其中 \(V + Ax + By \in [0, M]\)。如果 \(x, y\) 都是正数显然可以取 ......
AtCoder Regular Contest 127 177

Atcoder ABC321 笔记

A - 321-like Checker \(\color{gray}{22}\) 直接模拟 void solve() { int n; cin >> n; int lst = -1; for(int i = n; i; i /= 10) { int u = i % 10; if(u <= lst) ......
Atcoder 笔记 ABC 321

AtCoder Regular Contest 102

C - Triangular Relationship 枚举 \(a\bmod k\) 的值,\(b\bmod k,c\bmod k\) 的值也就确定了,算下贡献就好了。 #include<iostream> #include<cstdio> using namespace std; int n,k ......
AtCoder Regular Contest 102

AtCoder Regular Contest 103

C - //// 如果奇数和偶数出现的颜色的最大值相同一边取最大值和一边取次大值,否则两边都选最大值即可。 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=100005; ......
AtCoder Regular Contest 103

AtCoder Grand Contest 028

A - Two Abbreviations 答案要么就是 \(\operatorname{lcm}(n,m)\) 要么就是 \(-1\)。判断下 \(\operatorname{lcm}(n,m)\) 是否合法就是了。 #include<iostream> #include<cstdio> usin ......
AtCoder Contest Grand 028

AtCoder Grand Contest 027

A - Candy Distribution Again 从小到大贪心,可以发现一定是满足一个前缀,暴力判断就行了。 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N=10 ......
AtCoder Contest Grand 027

AtCoder Grand Contest 026

A - Colorful Slimes 2 可以发现,对于连续的一段长度为 \(m\) 的相同的字符,我们可以花费 \(\lfloor \frac{m}{2}\rfloor\) 的代价将它改为符合要求的。 #include<iostream> #include<cstdio> using names ......
AtCoder Contest Grand 026

AtCoder Grand Contest 025

A - Digits Sum 按题意模拟即可。 #include<iostream> #include<cstdio> using namespace std; const int INF=1061109567; int n; int calc(int x) { int res=0; while(x ......
AtCoder Contest Grand 025

AtCoder Grand Contest 024

A - Fairness 每次操作后 \(a_i-b_i=b_{i-1}-a_{i-1}\),对 \(k\) 的奇偶性讨论一下即可。 #include<iostream> #include<cstdio> using namespace std; int a,b,c; long long k; in ......
AtCoder Contest Grand 024

AtCoder Grand Contest 023

A - Zero-Sum Ranges 令 \(s_n=\sum\limits_{i=1}^n a_i\),相当于找满足 \(l\le r,s_r-s_{l-1}\) 的点对 \((l,r)\) 的个数,直接搞就完事了。 #include<iostream> #include<cstdio> #in ......
AtCoder Contest Grand 023

AtCoder Grand Contest 022

A - Diverse Word 如果至少有一个字符没有出现过,只要在原字符串后面加入一个没有出现过的字符中最小的那个字符就好了。 如果所有字符都出现过,找到一个尽量靠后的位置 \(i\in [1,n)\),使得 \(s_i\lt s_{i+1}\),最优字符串将 \(s_i\) 换成 \([i+1 ......
AtCoder Contest Grand 022

AtCoder Grand Contest 021

A - Digit Sum 2 要么是 \(n\) 要么是 \(n\) 的第一位后面加上若干个 \(9\)。 #include<iostream> #include<cstdio> #include<cmath> using namespace std; long long n; int calc( ......
AtCoder Contest Grand 021

AtCoder Grand Contest 041

A - Table Tennis Training 如果 \(n\) 为偶数,一个 \(+1\) 一个 \(-1\) 即可。 如果 \(n\) 为奇数,那么肯定有一个先到了 \(1\) 或 \(n\),然后再 \(+1,-1\),取个较小值即可。 代码: #include<iostream> #in ......
AtCoder Contest Grand 041

AtCoder Grand Contest 040

A - >< 将所有的连续段缩起来,如果这个区间为 <,则左端点为 \(0\),依次递增;如果这个区间为 >,则右端点为 \(0\),分界点取个左右的 \(\max\) 就好了。 #include<iostream> #include<cstdio> #include<cstring> using ......
AtCoder Contest Grand 040

AtCoder Grand Contest 039

A - Connection and Disconnection 对于连续的一段连续的长度为 \(L\) 的段,至少需要 \(\frac{L}{2}\) 次操作。判下头尾相等的情况,实现时注意细节即可。 #include<iostream> #include<cstdio> #include<cst ......
AtCoder Contest Grand 039

AtCoder Grand Contest 037

A - Dividing a String 可以发现,划分后的子串的长度不可能大于 \(2\)。令 \(f_{i,1/2}\) 表示到第 \(i\) 位,当前位置划分的子串长度为 \(1/2\) 的最大的 \(K\),转移枚举一下 \(i-1,i-2\) 即可。 #include<iostream> ......
AtCoder Contest Grand 037