codeforces&刷题笔记
刷题记录
_Koto
温顺的菜鸡
展开
-
1553(div1+div2)
A代码:int main() { IOS; int t; cin>>t; while(t--){ int n; cin>>n; n++; cout<<n/10<<endl; } return 0;}B题意:给定一个筹码,然后向左向右移动使得在字符串s种找到字符串t;同时向右移动玩只能向左移动;思路:因为在s字符串中可能存在多个解,同时原创 2021-08-01 01:45:21 · 290 阅读 · 0 评论 -
codeforces 1541B &1541C
1541B已知i和a[i]的情况下,要是i+j=a[i]*a[j],只需要使j满足i+j是a[i]的倍数推导(i+j)(i+j)(i+j)%a[i]=0a[i]=0a[i]=0iii%a[i]+ja[i]+ja[i]+j%a[i]=a[i]a[i]=a[i]a[i]=a[i]jjj%a[i]=a[i]−ia[i]=a[i]-ia[i]=a[i]−i%a[i];a[i];a[i];const int N=200010;int a[N];int main() { IOS; int t; c原创 2021-06-27 00:45:21 · 269 阅读 · 0 评论 -
codeforces 1424 G&J
1424G题意:有n个人,每个人都有出生和死亡时间,求存活人数最多的年份,以及存活人数;题解:假如一个人在b—d-1存活,在b——d-1标记成1,这里可以使用差分数组,给一个区间进行加减;由于年份可能非常大,因此使用map存储;#include <iostream>#include <algorithm>#include <map>using namespace std;#define x first#define y secondint main()原创 2021-06-01 22:26:19 · 260 阅读 · 1 评论 -
Atcode abc203 CD
C- Friends and Travel costs题意:一共有10100+1个村庄,刚开始在0号点,每走一步花费1块钱,起始有k块钱,途中又n个朋友,跟朋友相遇时可以获得bi块钱;题解:贪心模拟,遇到的朋友越多钱也就越多,走的也就越远;#include <iostream>#include <algorithm>using namespace std;const int N=200010;typedef long long ll;typedef pair<l原创 2021-05-31 22:50:57 · 278 阅读 · 0 评论 -
Codeforces 1458A gcd
1458A题意:给定两个数组 a和b,求gcd(a1+bj,a2+bj,…,an+bj);题解:gcd(a,b)=gcd(a,b-a),可以将上式转化为,gcd(a1+bj,a2-a1,…,an-a1)#include <iostream>#include <cmath>#include <algorithm>using namespace std;typedef long long ll;const int N = 200010;ll a[N], b[原创 2021-04-29 22:10:09 · 166 阅读 · 0 评论 -
Codeforces 1366C 贪心+思维
1366C题意:找到所有从1,1点到n,m点的路径并且使得所有路径都是回文数字的最小操作次数;思路:可以发现,从起点开始走k步,他走到的点是确定的,可以把这个当作是一个集合;一共会走n+m-2步,只需要是每一步的集合中的数组全部相等即可;#include <iostream>#include <algorithm>#include <cstring>#include <map>#include <set>using namespac原创 2021-04-29 09:00:44 · 128 阅读 · 0 评论 -
Codeforces 1364C
题意:通过数组a构建数组b;其中ai是MEX(b1~bi);思路:假如两个数字不同那么第i号元素一定是i-1号元素;假如相同的话;只需要从小到大一直添加即可;#include <iostream>#include <algorithm>#include <cstring>#include <map>#include <set>#include <vector>using namespace std;const int原创 2021-04-28 09:24:44 · 110 阅读 · 0 评论 -
Codeforces 1363B
题意:不能出现010或者101的子序列,求最小操作次数;思路:最后改变完要不出现上述子序列,只能是连续一部分0和连续一部分1拼接成的字符串,可以通过求改变成这种字符串的最小次数求解;#include <iostream>#include <algorithm>#include <cstring>#include <map>#include <set>using namespace std;const int N = 200010;原创 2021-04-28 08:23:27 · 105 阅读 · 0 评论 -
Codeforces 1444A 数学
1444A题意:找到最大的x,x满足整除p但是不能被q整除;题解:分为两种情况,假如ppp modmodmod q!=0q!=0q!=0,结果就是p剩下一种情况,可以将q分解质因数,枚举每一个质因子,这种情况下p一定能够被q整除,说明q的所有质因子p里面也有,并且都大于等于q的质因数的次方,要是p的因子不能被q整除,则p里面有q的某一个质因数的次方-1,通过枚举每个质因数得出最大值;#include <iostream>#include <algorithm>#in原创 2021-04-26 08:25:13 · 301 阅读 · 0 评论 -
Codeforces 1482C 贪心+模拟
题意:每天都可以选择给定数量的小朋友,但是每个小朋友被选的次数,不能超过m/2次(上取整);思路:硬贪,首先把每个小朋友的出现次数统计出来,假如出现次数小于m/2次这个就随便放,肯定不会超,然后找某一天个数为1的,这个必须放,这样可以避免前面放完之后,到后面不能放这个小朋友的情况,其他的按照次数放#include <iostream>#include <algorithm>#include <vector>#include <cstring>u原创 2021-04-25 23:35:54 · 168 阅读 · 0 评论 -
Codeforces 1506E 构造
1506E题意:两个数组a,b其中bi是max(a1~ai);,求字典序最大和最小的数组a;思路:数组b一定是逐渐上升的,假如两个相邻的元素相同那么第二个元素一定是小于前一个的;这个题可以使用优先队列来做,建立大根堆和小根堆,最大就插入大根堆堆顶,最小就插入小根堆堆顶;#include <iostream>#include <algorithm>#include <queue>#include <map>using namespace st原创 2021-04-24 18:17:51 · 151 阅读 · 0 评论 -
Codeforces 1490F 枚举+贪心
1490F题意:给了一串数字,通过从删除任意几个元素是数组中每个元素的个数都相同;题解:先统计出每个数字的个数,然后枚举保留个数,取得最优解#include <iostream>#include <algorithm>#include <map>#include <cmath>#include <set>using namespace std;const int N = 200010;#define x first#defin原创 2021-04-24 18:09:18 · 141 阅读 · 0 评论 -
Codeforces 1512E 思维+构造
1512E题意:找到给定区间长度并且区间和为s的序列;题解:序列可能有多种情况,可以采用较为连续的序列来表示,这样可以保证序列的每个值不会大于n;步骤:假如一个数字s,和区间长度len,用连续数字表示的话,每个数字之间就会相差1,首先把这个相差的1除去,然后就可以算出他们len个相同的初始的值,其中这个相差的值为int k=len*(len+1)/2-len,或者可以写成len*(len-1)/2,表示长度为len-1的公差为1的数列的和,s-=k;s/=len;,s就是初始值,每次加一原创 2021-04-24 17:52:25 · 190 阅读 · 0 评论 -
codeforces edu 107 div2
A.A找1和3的个数就可;#include <iostream>#include <algorithm>using namespace std;int a[100];int main() { int t; cin >> t; while (t--) { int n; cin >> n; int cnt1 = 0; for (int i = 1; i <= n; i++) { cin >> a[i];原创 2021-04-13 17:57:41 · 92 阅读 · 0 评论 -
并查集专题训练
搭配购买并查集+01背包;先合并分块,然后按照01背包模型求解#include <iostream>#include <algorithm>using namespace std;const int N = 10010;int p[N], c[N], d[N];int v[N], w[N];int find(int x) { if (x != p[x]) p[x] = find(p[x]); return p[x];}int f[N];...原创 2021-04-04 01:38:53 · 134 阅读 · 0 评论 -
基础dp专题训练
Max Sum Plus Plus#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>using namespace std;const int N = 1e5 + 10;typedef long long ll;ll a[N], f[N], max_j[N];const int INF =0x7fffffff;void solve() {...原创 2021-04-01 23:27:44 · 144 阅读 · 0 评论 -
基础搜索专题训练
1棋盘挑战#include<iostream>#include<algorithm>#include<cstring>using namespace std;const int N=20;char g[N][N];bool col[N],row[N];int n,k;int ans;void dfs(int u,int s){ if(s==k){ ans++; return; } if(u&g原创 2021-03-29 00:12:36 · 169 阅读 · 0 评论 -
codeforces#710
A题A思路:根据矩阵大小和给定的数字x找到他的坐标,然后计算新的数字就可以;#include<iostream>#include<algorithm>using namespace std;typedef long long ll;int main(){ int t; cin>>t; while(t--){ ll n,m; cin>>n>>m; ll x;原创 2021-03-26 01:53:19 · 148 阅读 · 0 评论 -
动态规划
动态规划实质上时枚举出每种状态然后找出最优解;枚举一般用循环或者递归来实现:1.斐波那契数列要计算第n项的值就必须计算出n-1和n-2的值,计算n-1,必须先计算出n-2和n-3的值,一直到1和2为止;int fun(int n){ if(n==1) return 1; if(n==2) return 2; return fun(n-1)+fun(n-2);}画出图像之后会发现有大量的重叠子问题,这些重叠子问题可以避免重复计算,使用一个数组把已经计算过的值存储起来,需原创 2021-01-11 15:50:02 · 276 阅读 · 0 评论 -
cf 1492C
题目链接:1492C思路:=贪心,他要找到最宽的距离 ,也就是子序列之间最大的差;先找出第一次出现的子序列和最后一次出现的子序列,所有的子序列的下标肯定都在这个范围内,所以用最大的减去前一个字母最小的下标即可;/*思维/贪心算法:要求宽度最大;只需要把第一次出现的子序列和最后一次出现的子序列的位置找出来然后找到最大得到r[i]-l[i-1]即可*/#include<iostream>#include<algorithm>using namespace st原创 2021-03-23 09:36:52 · 62 阅读 · 0 评论