
cf之旅
逆水行舟,不进则退
开学了8
go on
展开
-
1672D - Cyclic Rotation
1672D - Cyclic Rotation逆向思维:b 能否转成 a ?选择一个位置 j, bj−1==bjb_{j-1} == b_jbj−1==bj, 那么可以把 j-1 这个位置的值放到前面去双指针实现:if(bj==ai)if(b_j ==a_i)if(bj==ai) i ++, j ++;if(bj==bj−1)if(b_j == b_{j-1})if(bj==bj−1) 在mutiset中寻找是否出现过 bj−1b_{j-1}bj−1 ,如果出现过意味着可以把它插原创 2022-04-29 09:50:32 · 157 阅读 · 0 评论 -
1672D - Cyclic Rotation
1672D - Cyclic Rotation逆向思维:b 能否转成 a ?选择一个位置 j, bj−1==bjb_{j-1} == b_jbj−1==bj, 那么可以把 j-1 这个位置的值放到前面去双指针实现:if(bj==ai)if(b_j ==a_i)if(bj==ai) i ++, j ++;if(bj==bj−1)if(b_j == b_{j-1})if(bj==bj−1) 在mutiset中寻找是否出现过 bj−1b_{j-1}bj−1 ,如果出现过意味着可以把它插原创 2022-04-29 09:49:47 · 101 阅读 · 0 评论 -
1672D - Cyclic Rotation
1672D - Cyclic Rotation逆向思维:b 能否转成 a ?选择一个位置 j, bj−1==bjb_{j-1} == b_jbj−1==bj, 那么可以把 j-1 这个位置的值放到前面去双指针实现:if(bj==ai)if(b_j ==a_i)if(bj==ai) i ++, j ++;if(bj==bj−1)if(b_j == b_{j-1})if(bj==bj−1) 在mutiset中寻找是否出现过 bj−1b_{j-1}bj−1 ,如果出现过意味着可以把它插原创 2022-04-28 18:59:32 · 367 阅读 · 0 评论 -
I. Ice Cream Shop
原创 2022-04-25 12:36:36 · 238 阅读 · 0 评论 -
C - Chat Ban
C - Chat Ban注意二分边界条件吧// Problem: C. Chat Ban// Contest: Codeforces - Educational Codeforces Round 117 (Rated for Div. 2)// URL: https://codeforces.com/contest/1612/problem/C// Memory Limit: 512 MB// Time Limit: 2000 ms// // Powered by CP Editor (ht原创 2022-03-03 23:26:57 · 313 阅读 · 0 评论 -
E1 - Escape The Maze (easy version)(双向广搜)
有一个无向图,Vlad和他的k个朋友分别在不同的房间,Vlad在一号房如果Vlad走到一个只有一条通道的房间,他就获胜如果他的朋友在途中遇到他,则朋友获胜每个单位时间,每人可以移动一个单位距离。解法:双向广搜初始队列:每个被朋友占领的节点+Vlad所在的节点遍历队列,如果这个节点没有被占领过,相邻的节点优先占领// Problem: E1. Escape The Maze (easy version)// Contest: Codeforces - Codeforces Round #756原创 2022-03-02 19:56:25 · 349 阅读 · 0 评论 -
D. Weights Assignment For Tree Edges (数+构造)
D. Weights Assignment For Tree Edges给定b数组:对于b数中的一个数,bib_ibi 是i个祖先给定一个排列p,要求dist[p[i]]<dist[p[i+1]]dist[p[i]] < dist[p[i+1]]dist[p[i]]<dist[p[i+1]] ,也就是说p排列给了从根节点到各个节点距离大小关系。dist[i]dist[i]dist[i] 表示从根节点到当前节点的距离(1)根节点的dist[p[1]]=0dist[p[1]]=0di原创 2022-03-01 20:32:20 · 585 阅读 · 0 评论 -
D. Yet Another Sorting Problem (偶排列)
奇偶排列:一个排列中,如果交换两个数,那么它排列的奇偶性一定发生变化。参考:百度-奇排列-性质1(1)考虑数组中的数两两不相同:比较当前数组与不下降数组之间排列奇偶性。如果它们排列的奇偶性相同,可以变化,否则不行。具体请自行证明。(2)数组中有相同的数:数组逆序对奇偶性可以随意转换,就一定能转换为不下降子序列。逆序对树:acwing板子// Problem: D. Yet Another Sorting Problem// Contest: Codeforces - Codeforces Ro原创 2022-03-01 13:46:50 · 281 阅读 · 0 评论 -
1614C Divan and bitwise operations
尺取法模板注意 每次取出的钱不能超过ATM机剩余的余额:sum+a[t]+S>=0sum + a[t] + S >= 0sum+a[t]+S>=0typedef long long ll;const int N = 2e5+10;int n;ll S, a[N];void solve(){ scanf("%d %lld", &n, &S); for(int i = 1; i <= n; i++) scanf("%lld", &a[i])原创 2021-11-29 16:29:30 · 690 阅读 · 0 评论 -
Educational Codeforces Round 117 (Rated for Div. 2)
a稍微进行分类讨论#include <iostream>using namespace std;#define eps 1e-8const int maxn = 1e6; void solve(){ int a, b, x, y; // c(x, y); // A(0,0) B(x,y) scanf("%d %d", &a, &b); int dis_ac = x + y; // 2x + 2y = a + b; ---- (1) // 2abs(a原创 2021-11-25 10:34:43 · 502 阅读 · 0 评论 -
1598B
给定n * m 的网格,一开始全部涂成红色。有两种操作,一种是切割,一种是涂蓝色。切割的限制:不能切成1*1 的网格,可以切无限次;涂蓝色没有限制。涂蓝色最少多少次,可以使得相邻的网格颜色不一样?通关观察可以发现,切割成1* 3 或者 3 * 1 的网格比较划算,此时的红蓝比是 2:1按列3个一切, 列可以切多少次呢? int y = (int)floor(1.0*m / 3),此时有n行因此:ans = y * n。 3个一切如果剩下一列,那么ans += (int)floor(1.原创 2021-11-15 08:38:15 · 246 阅读 · 0 评论 -
F. Fixing Banners
// Problem: F. Fixing Banners// Contest: Codeforces - The 2019 China Collegiate Programming Contest Harbin Site// URL: https://codeforces.com/gym/102394/problem/F// Memory Limit: 512 MB// Time Limit: 1000 ms// // Powered by CP Editor (https://cpedito原创 2021-11-01 15:17:42 · 115 阅读 · 0 评论 -
Third-Party Software - 2(贪心+最小覆盖问题)
#include<iostream>#include<cstdio>#include<string>#include<ctime>#include<cmath>#include<cstring>#include<algorithm>#include<stack>#include<climits>#include<queue>#include<map>#in原创 2021-10-26 20:33:35 · 142 阅读 · 0 评论 -
Codeforces Round #750 (Div. 2) a-d
//all a, b, c;void solve(){ cin >> a >> b >> c; ll sum = a + 2*b + 3*c; if(sum&1) cout << 1 << endl; else cout << 0 << endl; }//bint n, m;ll a[N];ll qmi(ll a, ll b){ ll res = 1; while(b) {原创 2021-10-26 20:32:11 · 86 阅读 · 0 评论 -
贪心(排序)
https://codeforces.com/gym/102215/problem/F#include <iostream>#include <cstring>#include <algorithm>#define PII pair<int,int>using namespace std;#define ll long longconst int N =3e5 + 10;int n;struct Node { ll a, b;原创 2021-10-26 20:29:19 · 62 阅读 · 0 评论 -
M. Camouflage (搜索)
从外层开始搜,标记哪些在外围的点找到内层的点,记录要涂的点数,合适就填上。// Problem: M. Camouflage// Contest: Codeforces - The 15-th BIT Campus Programming Contest - Onsite Round// URL: https://codeforces.com/gym/102878/problem/M// Memory Limit: 256 MB// Time Limit: 1000 ms// // Powe原创 2021-10-13 21:39:41 · 141 阅读 · 0 评论 -
C. Portal
https://codeforces.com/contest/1581/problem/C暴力n^4 方,当枚举最后一列之前,判断是否大于16,大于就剪枝,16是最坏情况下的修改数为什么16是最坏情况呢?想想,5行4列,四个边角不需要改变,那就是4*5 - 4 = 16;先枚举行,再枚举列,枚举最后一列的时候,之前的矩形需要修改的数量已经是确定好了,如果已经确定好的数都大于最坏情况,直接break;然后就是一些预处理啦, 保证每次在O(1)时间内算出当前方案需要修改的数。// Problem:原创 2021-09-30 22:23:31 · 214 阅读 · 0 评论 -
D. Productive Meeting (大根堆)
放到堆里,每次取出堆顶的两个元素来判断就好了// Problem: D. Productive Meeting// Contest: Codeforces - Codeforces Round #744 (Div. 3)// URL: https://codeforces.com/contest/1579/problem/D// Memory Limit: 256 MB// Time Limit: 2000 ms// // Powered by CP Editor (https://cpedi原创 2021-09-29 19:10:33 · 287 阅读 · 0 评论 -
B. Shifting Sort (思维)
思路大家都能想到,代码不是很好写// Problem: B. Shifting Sort// Contest: Codeforces - Codeforces Round #744 (Div. 3)// URL: https://codeforces.com/contest/1579/problem/B// Memory Limit: 256 MB// Time Limit: 2000 ms// // Powered by CP Editor (https://cpeditor.org)c原创 2021-09-29 17:43:44 · 480 阅读 · 0 评论 -
C. Strange Function (思维+数论)
1 2 3 ... x−11 \ 2 \ 3 \ ... \ x-11 2 3 ... x−1 是 iii 的因子, xxx 不是 iii 的因子容易得出lcm(1,2,...,x−1)lcm(1, 2, ...,x-1)lcm(1,2,...,x−1) 是 iii 的因子,但lcm(1,2,3...,x−1,x)lcm(1, 2, 3...,x-1, x)lcm(1,2,3...,x−1,x) 不是 iii 的因子对于.原创 2021-09-28 12:42:08 · 241 阅读 · 0 评论 -
D Array Differentiation
假设b[i] 为点权, a[i] 为边权,连成树,只有 n-1 条边,如果其中有环,则有至少n条边。判断是否有环:其中的元素相加是否是0;可以用dfs 或者 直接遍历const int N=110;int n, ans;int a[N];set<int> q;void dfs(int x, int s){ if(x > n) { if(q.count(s)) ans = 1; q.insert(s); return ; } if(ans) retur原创 2021-09-27 12:59:12 · 135 阅读 · 0 评论 -
B. Running for Gold (结构体排序)
https://codeforces.com/contest/1552/problem/B写了很久,发现是个简单的排序题// Problem: B. Running for Gold// Contest: Codeforces - Codeforces Global Round 15// URL: https://codeforces.com/contest/1552/problem/B// Memory Limit: 256 MB// Time Limit: 1000 ms// // Po原创 2021-09-26 19:35:47 · 102 阅读 · 0 评论 -
C - Book 拓扑排序
https://codeforces.com/contest/1573/problem/C判断还有度的节点一定放在最后注意更新的操作:如果比当前节点小,当前节点加一再比较,否则直接比较最后输出最大的操作次数就可以。#include<bits/stdc++.h>using namespace std;const int N = 2e5 + 10;vector<int> to[N];int main() { ios::sync_with_stdio(false); ci原创 2021-09-24 10:50:39 · 94 阅读 · 0 评论 -
B. Swaps
https://codeforces.com/contest/1573/problem/B思路:答案 = 奇数交换的次数 + 偶数交换的次数固定一个值,更新另外一个值就可以,固定哪个都是一样的,是个镜像操作。更新操作:先按照原来的排序方式,分配好初始位置,从大到小更新,最大的位置没法更新,分配初始位置 and 另外一个数组的起始位置 是从1开始的,所以要减两个1// Problem: B. Swaps// Contest: Codeforces - Codeforces Round #743 (D原创 2021-09-23 12:28:08 · 233 阅读 · 0 评论 -
D. The Strongest Build
给 n 个slots,每个slots 有若干个卡片,每个卡片上的数值都可以提升英雄的实力(数值已经升序排好)告诉你,有一些卡片的序号被banned,不能使用,剩下哪些卡片可以使得英雄的实力总和最大,要求输出卡片的序号。比如说,第i个slots 有对用三个卡片,第三个卡片被baned ,那么你选择的序号是二,因为二肯定大于等于一。输出所有的序号,保证一定有答案。https://codeforces.com/contest/1574/problem/D题解:(1)二维数组如果过大,会爆内存(2)记录原创 2021-09-22 23:52:43 · 128 阅读 · 0 评论 -
括号串 思维
随便猜一下就可以// Problem: A. Regular Bracket Sequences// Contest: Codeforces - Educational Codeforces Round 114 (Rated for Div. 2)// URL: https://codeforces.com/contest/1574/problem/0// Memory Limit: 512 MB// Time Limit: 2000 ms// // Powered by CP Editor原创 2021-09-21 10:35:32 · 68 阅读 · 0 评论 -
Combinatorics Homework 思维
判断最大值和最小值,看给的数值是否位于区间中。// Problem: B. Combinatorics Homework// Contest: Codeforces - Educational Codeforces Round 114 (Rated for Div. 2)// URL: https://codeforces.com/contest/1574/problem/B// Memory Limit: 256 MB// Time Limit: 2000 ms// // Powered b原创 2021-09-21 10:34:47 · 363 阅读 · 0 评论 -
Slay the Dragon 二分 + 贪心
二分+贪心找到最小花费,主要是边界有点麻烦// Problem: C. Slay the Dragon// Contest: Codeforces - Educational Codeforces Round 114 (Rated for Div. 2)// URL: https://codeforces.com/contest/1574/problem/C// Memory Limit: 256 MB// Time Limit: 2000 ms// // Powered by CP Edit原创 2021-09-21 10:30:56 · 250 阅读 · 0 评论 -
cf交互题
链接#include <iostream>#include <algorithm>using namespace std;const int N = 1e4 + 10;int a[N], b[N];int main(){ int n, k; scanf("%d %d", &n, &k); for(int i = 1; i <= n - 1; i++) { printf("and %d %d\n", i, i+1); fflu原创 2021-08-30 17:44:40 · 396 阅读 · 0 评论 -
Codeforces Round #739 (Div. 3)(编辑距离+数位dp)
aint n;int arr[N]; void solve(){ cin >> n; cout << arr[n] << endl;} int main(){ ios::sync_with_stdio(false);cin.tie(0); int x = 1; rep(i,1,100000) { if(i%3==0 || i%10==3) continue; else arr[x++]=i; } int Case;cin &g原创 2021-08-19 12:42:51 · 103 阅读 · 0 评论 -
C - Mocha and Hiking(模拟)
第一次错误:没有考虑到走到中间的位置d,然后直接走到n+1,接着走d+1一直走到n,这样的情况就是判断是否 满足:第i个位置为0,第i+1个位置为1第二次错误:处理边界的时候大意了,把受到:原题目中n没有路到n+1的影响,直接i < n ,实际上是i <= n;// Problem: C. Mocha and Hiking// Contest: Codeforces - Codeforces Round #738 (Div. 2)// URL: https://codeforces.co原创 2021-08-18 19:42:15 · 190 阅读 · 0 评论 -
B. Mocha and Red and Blue(贪心)
(1)如果第一个位置是问号,分别把当做是R/B,往下模拟(2)如果第一个位置是B,那就直接往下模拟(3)如果第一个位置是R,还是直接往下模拟第二个和第三个只需要一个字符串组就可以完成,但为了copy代码,以及适应下面的求和取最小的计算,需要变成两个字符串组。// Problem: B. Mocha and Red and Blue// Contest: Codeforces - Codeforces Round #738 (Div. 2)// URL: https://codeforces.co原创 2021-08-18 15:25:08 · 193 阅读 · 0 评论 -
D. Backspace(逆序处理)
首先排除两种容易想到的情况每次删除,必须删除偶数个,先找到最后一个,当然最后一个的时间不能小于m,因为要一一对应的话,最少也是m个。找到了第一个,按照相同则对应一一减少,不相等则第一个每次减少偶数次,直到最后都相等。// Problem: D. Backspace// Contest: Codeforces - Harbour.Space Scholarship Contest 2021-2022 (open for everyone, rated, Div. 1 + Div. 2)// URL:原创 2021-08-06 20:02:01 · 369 阅读 · 0 评论 -
B. Reverse String(brute force)
给的范围小,数据水,暴搜为什么说数据水? 对于每个字母,直接往后搜到最后一个就行,不用管到第一个后返回从第二个开始。例如abcdddabab答案是搜不到,数据也不给这样类型的额,回去读了读题目,发现题目读错了就是右几步,然后往左几步,没有说,来回反复多次重复往返。这样代码就简单了// Problem: B. Reverse String// Contest: Codeforces - Harbour.Space Scholarship Contest 2021-2022 (open f原创 2021-08-06 12:43:06 · 96 阅读 · 0 评论 -
(D) Diane
闭着眼睛过的// Problem: D. Diane// Contest: Codeforces - Codeforces Round #735 (Div. 2)// URL: https://codeforces.com/problemset/problem/1554/D// Memory Limit: 256 MB// Time Limit: 1000 ms// // Powered by CP Editor (https://cpeditor.org)#include<iost原创 2021-08-06 00:35:31 · 111 阅读 · 0 评论 -
B. Cobb
f(i,j)=i∗j−k∗(ai∣aj)f(i,n)=i∗n−k∗(0∣0)=i∗n;(含i且最大)f(n−1,n)=n∗(n−1)−k∗2n=n2−2kn−n(最小的情况)f(i,n)>f(n−1,n−1)==ni>n2−2nk−ni>n−2k−1f(i,j) = i * j - k * (a_i | a_j) \\f(i,n) = i *n - k * (0|0) = i * n; (含i且最大) \\f(n-1,n) = n*(n-1) - k * 2n = n^2 - 2kn原创 2021-08-05 14:38:32 · 97 阅读 · 0 评论 -
A. Cherry
任意选定一个数, 如果左边的数小于它,如果和它相同,则替换;如果比它小,则再往左就不用考虑了,如果比它大则直接选定,最后都递归到选定左右最大的乘积。#include <iostream>#define rep(i,l,r) for(int i = l; i <= r; i++)#define ll long longusing namespace std;const int N = 1e5 + 10;int arr[N];int main(){ int Case;原创 2021-08-05 11:42:29 · 91 阅读 · 0 评论 -
C. Coin Rows(读入要全)
不管是否需要,每一个样例要全部读入,否则没有读入的数据会被下一个样例继续使用,造成错误#include <iostream>#include <cmath>#include <cstring>#define ll long longusing namespace std;const int N = 1e5 + 10;int arr[N], brr[N]; ll sum1[N], sum2[N];int main(){ int Case; c原创 2021-08-04 21:12:32 · 245 阅读 · 0 评论 -
1555B - Two Tables
写了半天,发现两行代码搞定!MAX_INT 可以直接用#include <iostream>#include <cmath>#define ll long longusing namespace std;int main(){ int Case; cin >> Case; while(Case--) { double W, H, x1, y1, x2, y2, w, h; cin >> W >> H >>原创 2021-08-04 15:25:33 · 88 阅读 · 0 评论 -
D. Say No to Palindromes(全排列,找规律)
产生排列的方式点击#include <iostream>#include <algorithm>#include <vector>using namespace std;const int N = 2e5+10;int n, m;char a[N];int s[6][N];vector<string> neg;void init(){ neg.push_back("abc"); for(int i=0;i<6;i++)原创 2021-08-03 22:55:27 · 143 阅读 · 0 评论