- 博客(21)
- 收藏
- 关注
原创 2022牛客多校7 A Floor Tiles in a Park
2022牛客多校7 A Floor Tiles in a Park 拉格朗日插值解法
2022-09-09 21:03:52
305
原创 查询数组中能被k整除且不小于z的连续子序列和的个数
题目:小圆前辈的数组小圆前辈最近收到了一个长度为nnn数组。她怀疑是不怀好意的魔女给她的陷阱,于是她对数组进行了剖析后发现了两个关键的整数kkk和zzz,而解读此数组只要算出的所有连续子序列中有多少满足:1,所有数的和为kkk的倍数;2,且其和至少为zzz;这个问题难到了小圆前辈,她便把这个问题交给了你,如果你能帮她解决的话,她将奖励你一个Accept。输入描述:第一行只有三个整数n,k,zn,k,zn,k,z。第一行共n个整数a[1]...a[n]a[1]...a[n]a[1]...a[n
2021-10-16 16:00:06
336
原创 专题训练——并查集
并查集分类:#mermaid-svg-XFMSSLLMqpqg3iIV .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-XFMSSLLMqpqg3iIV .label text{fill:#333}#mermaid-svg-XFMSSLLMqpqg3iIV .node rect,#mermaid-svg-XF
2021-10-15 09:01:23
146
原创 用lower_bound简化最长上升子序列代码
小知识本质上为二分查找所以序列必须升序(定义序列大小后降序也可以)lower_bound会找出序列中第一个大于等于x的数upper_bound会找出序列中第一个大于x的数差别在于是否包含等于x的数用法:lower_bound(a,a+n,x);//在a[]中找到第一个不大于x的数lower_bound(a,a+n,x,cmp);//实际上还可以加上比较函数lower_bound(a,a+n,x,greater<int>());//这样就改为降序序列该函数的返回值是一个指
2021-10-06 19:20:38
225
原创 归并排序
归并排序如题:给定你一个长度为 n 的整数数列。请你使用归并排序对这个数列按照从小到大进行排序。并将排好序的数列按顺序输出。输入格式输入共两行,第一行包含整数 n。第二行包含 n 个整数(所有整数均在 1∼109 范围内),表示整个数列。输出格式输出共一行,包含 n 个整数,表示排好序的数列。数据范围1≤n≤100000代码如下:#include<iostream>using namespace std;const int N=1e5+5;int a[N]
2021-05-04 14:49:31
427
原创 快排(第k个数)
第k个数如题:给定一个长度为 n 的整数数列,以及一个整数 k,请用快速选择算法求出数列从小到大排序后的第 k 个数。输入格式第一行包含两个整数 n 和 k。第二行包含 n 个整数(所有整数均在 1∼109 范围内),表示整数数列。输出格式输出一个整数,表示数列的第 k 小数。数据范围1≤n≤100000,1≤k≤n代码如下#include<iostream>using namespace std;const int N=1e5+5;int a[N],n,k
2021-05-04 13:54:51
162
原创 Codeforces Round #696 (Div. 2) B. Different Divisors题解
思路:素数筛法由题设可知,4个因子分别是1,a,b,n(a,b均为素数)为了节省时间,不妨先把1~40000的素数先筛出来。代码:#include <cstdio>#include <iostream>#include <cmath>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;const int n=
2021-01-25 17:06:20
162
原创 Codeforces Round #632 (Div. 2) A - Puzzle From the Future题解
思路:贪心的构造1,不能构造1就构造0。我的代码:#include <cstdio>#include <iostream>#include <cmath>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;char a[100005];void solve(){ int n; int i,i1,i2,te
2021-01-25 14:24:30
124
原创 Codeforces Round #640 (Div. 4) G. Special Permutation题解
思路:当n<4时显然不存在,当n>=4时,构造……n-4,n-2,n,n-3,n-1,n-5,n-7……。代码:#include <cstdio>#include <iostream>#include <cmath>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;void solve(){
2021-01-25 13:50:25
127
原创 Codeforces Round #640 (Div. 4) F. Binary String Reconstruction题解
思路:构造类似于00……0011……1101010……的字符串,注意考虑n0,n1,n2分别为0的情况。代码:#include <cstdio>#include <iostream>#include <cmath>#include <string.h>#include <stdlib.h>#include <algorithm>using namespace std;void solve(){ int n0,n
2021-01-25 13:42:36
96
原创 Codeforces Round #640 (Div. 4) E. Special Elements题解
代码:#include<iostream>using namespace std;int a[8005];bool b[8005];void solve(){ int n; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; b[i]=false; } for(int i=1;i<=n;i++) { for(int sum=a[i],j=i+1;j<=n;j++) { su
2021-01-22 09:25:48
110
原创 Codeforces Round #640 (Div. 4) D. Alice, Bob and Candies题解
题解:简化代码:#include<iostream>using namespace std;int ac[1005];void solve(){ int n,i; cin>>n; for(i=0;i<n;i++)cin>>ac[i]; int a=0,b=0,an=0,bn=0,bs=0,l=0,r=n-1; while(l<r) { for(a=0;a<=b&&l<=r;l++) a+=ac[l]
2021-01-21 15:20:46
157
原创 不能被n整除的第k个数(n>2)
笔记:小技巧简化代码:int n,k;cin>>n>>k;cout<<k/(n-1)*n+(k%(n-1)?k/(n-1):-1)<<endl;相关题目:Codeforces Round #640 (Div. 4) C — K-th Not Divisible by n
2021-01-21 14:11:11
593
原创 关于拆分一个整数(如123→100+20+3)
笔记:拆分一个整数简化代码:int n,i=1,a[101],an=0;cin>>n;while(n){ if(n%10!=0)a[an++]=n%10*i; n/=10; i*=10;}这样可以得到拆分后数字的数量an和拆分后的数组a[]相关题目:Codeforces Round #640 (Div. 4) A — Sum of Round Numbers...
2021-01-21 13:19:44
157
原创 Codeforces Round #685 Div. 2 C 题解
从第一步操作可以得到程序的结果与字母的顺序无关,所以不妨转化为数组z[26][2]来储存a,b字符串字母的数量。而第二步操作中如果直接按照题设的步骤来做,即对a字符串进行“k个相同字母+1”那么写出的代码会十分繁琐,且不容易打出正确的代码。所以我们不妨逆向操作对b字符串进行“k个相同字母-1”即:z[i][1]-=k;z[i-1][1]+=k;并从最大的字母z(也就是25(z-97=25))开始进行操作int i=25;while(i){ ....... z[i][..
2021-01-02 15:50:09
176
原创 Codeforces Round #684 Div. 2 C1题解
观察下列四种类型的2×2矩形"1"的个数举例10001200113011141111我们首先确定2×2矩形的位置1 23 4“1”有2个或4个时每一个“1”处进行一次 操作 即可还原。(1) “1”有2个时00 → 11 → 0011 → 10 → 00(2) “1”有4个时11 → 01 → 0011 → 00 → 11接下来同上而“1”有1个或3个时对每个“0”进行一次操作即可(3) “1”有3个时11 → 00.
2020-12-31 18:42:13
103
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人