自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(55)
  • 收藏
  • 关注

原创 后缀数组模板

后缀数组模板#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int N = 1000010;int n, m;char s[N];int sa[N];//排名第i位第是第几个后缀int rk[N];//第i个后缀排名是多少int height[N];//sa[i]和sa[i-1]第最长公共前缀int x[N], y[N], c

2021-07-30 13:38:59 104

转载 莫队算法模板

朴素莫队#include <bits/stdc++.h>#define N 100005using namespace std;inline int read(){ register int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=(x<<3)+(x<&l

2021-07-22 10:31:08 182

转载 树状数组模板

#include <bits/stdc++.h>using namespace std;int n,m;int a[50005],c[50005]; //对应原数组和树状数组int lowbit(int x){ return x&(-x);}void updata(int i,int k){ //在i位置加上k while(i <= n){ c[i] += k; i += lowbit(i); }}

2021-07-22 10:27:26 101

原创 #10024. 「一本通 1.3 练习 3」质数方阵

#10024. 「一本通 1.3 练习 3」质数方阵***思路:***素数筛找出数位和符合条件的素数预处理可能成为答案的数dfs#include<bits/stdc++.h>using namespace std;typedef long long ll;//素数筛//找出数位和符合条件的素数//预处理可能成为答案的数//dfs#define MAXNUM 100006bool is_prime[MAXNUM];int prime1[MAXNUM];int prim

2021-05-07 13:17:01 462

原创 子序列回文模板

#include<iostream>#include<algorithm>using namespace std; //动态规划求解最长回文子序列,时间复杂度为O(n^2)int lpsDp(char *str, int n){ int dp[10][10], tmp; memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; ++i) dp[i][i] = 1; for (int i = 1; i <

2021-03-21 16:01:31 59

原创 阶乘因式分解

#include <cstdio>#include <iostream>using namespace std;int main(){ int x; int n,m; int i; int sum[100]={0}; cin>>x; for(i=0;i<x;i++) { cin>>n>>m; while(n) { n/=m; //这两行为核心 sum[i]+=n

2021-03-16 17:03:35 61

原创 大数快速质因数分解模板

#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<iostream>#include<queue>using namespace std; typedef long long ll;const int maxn = 105;ll x[maxn], ans;queue<ll> aria;ll min(l

2021-03-16 16:42:38 259

原创 素数求区间中的素数(区间筛法)

#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<map>#include<vector>#include<queue>#include<stack>using namespace std;#define LL long long#define MAX_L 1000007#define M

2021-03-16 14:24:16 268

转载 区间dp(模板+优化)

模板memset(dp,0,sizeof(dp))//初始dp数组for(int len=2;len<=n;len++){//枚举区间长度 for(int i=1;i<n;++i){//枚举区间的起点 int j=i+len-1;//根据起点和长度得出终点 if(j>n) break;//符合条件的终点 for(int k=i;k<=j;++k)//枚举最优分割点 dp[i][j]=min(dp[i]

2021-02-07 14:45:05 127

原创 状压dp入门

状压dp入门什么是状态压缩dp?状态压缩dp就是把某些用dfs会超时的递归调用过多的题目转换成用数组中的一位数表示状态。我们知道在二进制下每一位上不是0就是1,这样就可以很好的表示事物的状态,是存在还是不存在,状态压缩就是把状态压缩到一位数内,这一位数操作时都用二进制操作。要学状态压缩dp首先要对二进制有所了解。我们下面来介绍一下二进制的相关知识。1.’&’符号,x&y,会将两个十进制数在二进制下进行与运算,然后返回其十进制下的值。例如3(11)&2(10)=2(10)。2

2021-02-06 12:52:25 815

转载 数位dp总结(模板+例题)(从入门到放弃)

转载自:https://blog.csdn.net/wust_zzwh/article/details/52100392数位dp模板:typedef long long ll;int a[20];ll dp[20][state];//不同题目状态不同ll dfs(int pos,/*state变量*/,bool lead/*前导零*/,bool limit/*数位上界变量*/)//不是每个题都要判断前导零{ //递归边界,既然是按位枚举,最低位是0,那么pos==-1说明这个数我枚举完了

2021-02-02 15:36:38 619

原创 Codeforces Round #698 (Div. 2)

A Nezzar and Colorful Balls题意: 有一串非递减数列,你要涂色,保证有相同颜色的数组都是严格递增的,问最少要几种颜色。思路: 直接找最多有几个相同的数就行了。#include<bits/stdc++.h>using namespace std;typedef long long ll;int a[1007];int main(){ int t; scanf("%d",&t); while(t--) { memset(a,0,sizeo

2021-01-29 11:31:10 117

原创 Codeforces Round #691 (Div. 2)

A. Red-Blue Shuffle题意: 有n张片,每张卡牌上有两个数字,一个在上面是红色一个在下面是蓝色,我们可以按任意顺序排卡牌,然后按照上面的数字顺序把数字组合出来,红色的大就是红色的赢,蓝色大就是蓝色赢。求出谁赢的概率大。思路: 实际上我们只需要看每张卡片上是红色大还是蓝色大,然后看是红色大的卡片数量多就是红色概率大,反之也成立。#include<bits/stdc++.h>using namespace std;typedef long long ll;char a[1

2021-01-28 11:35:42 143

原创 ACM-ICPC Shenyang Oniste 2018 Best ACMer Solves the Hardest Problem

ACM-ICPC Shenyang Oniste 2018 Best ACMer Solves the Hardest Problem思路: 用map或者二维数组存点,然后先预处理出每个点的属于哪个k值,存在vector pair中,最后根据操作直接找就行了。如果是用二维数组存点的话,还要用vector把存进去的点记录下来,然后清空,不然直接memset会超时。#include<bits/stdc++.h>using namespace std;typedef long long

2021-01-23 18:01:39 91

原创 ACM-ICPC 2017 Asia Urumqi Coins

ACM-ICPC 2017 Asia Urumqi Coins题意: 有n个硬币全部正面朝下,你有m次操作,每次操作选择k个硬币抛起来,问在最优策略下,你得到数量最多的朝上的硬币数量的期望。思路: 我一开始想到的是dfs,但是感觉不行,复杂度太高了,后来又想到用概率dp做,我们每一次抛起来,规定现在有几个正面,然后去推这一次抛完后有几个正面,,最后得到概率,乘上期望就好了。但是dp的时候要注意类讨论,有一种情况是我们剩下的反面硬币不足k个,就需要用到已经是正面的硬币,这时候dp就要减去被卷进来的本来已

2021-01-22 16:30:20 99

原创 ACM-ICPC 2017 Asia Nanning E - The Champion

ACM-ICPC 2017 Asia Nanning E - The Champion题意: 有r场对局,2^r个人,你在当中实力排在第k位,当一个强的人跟弱的人打的时候,强的人赢的概率是p。你可以自由安排大家对局,最后留下来的人是胜者,问怎么安排对局你自己的胜率最高,最高是多少,输出。思路: 我们很容易想到你只有多更比你弱的人打,你成为最终胜者的概率才会越高。所以最优的情况是你跟弱者打,强者内部打,弱者内部打。直到一方没有。但是有个问题就是当强者的人数时奇数时,你就需要判断两种情况,一种是强者赢了,一

2021-01-21 17:59:45 118

转载 线性基+线段树模板

t组数据,n个数的序列,q次查询,取l,r区间中的数,使得这些数异或后 或 (|)上k的最大值。#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;typedef long long LL;struct tree{ LL l, r; LL d[70];}t[40010];LL a[10010],

2021-01-20 16:32:45 58

转载 2017 ACM 区域赛青岛站(现场赛) K Our Journey of Xian Ends

2017 ACM 区域赛青岛站(现场赛) K Our Journey of Xian EndsLife is a journey, and the road we travel has twists and turns, which sometimes lead us to unexpected places and unexpected people. Now our journey of Xian ends. To be carefully considered are the following q

2021-01-19 17:05:04 120

原创 2020年广东工业大学第十届文远知行杯新生程序设计竞赛(同步赛)(详细题解)

A 肥猪的钢琴床思路: 我比赛的时候是没做出来,没往dp想,后来赛后看大佬代码才知道正解。我们发现对于每个点来说,都有两种情况,一种是取1留0,一种是取0留1,这正好是吻合了dp的想法,还有一种极端情况是把前面的所有的1全部去掉。所以我们就获得了三个dp式子dp[i][0]=dp[i-1][0]+a[i]-‘0’;dp[i][1]=min(dp[i-1][1]+‘1’-a[i],dp[i-1][0]+‘1’-a[i]);dp[i][2]=min(dp[i-1][1]+a[i]-‘0’,dp[i-1]

2020-12-06 20:57:35 702 2

原创 Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2)——D XOR-gun(思维)

Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2)——D XOR-gun题意: 给你一个非递减数组,你可以把其中任意两个相邻的数进行异或,然后把新的数放入原来的位置。问最少要几步可以把这个数组变成无序的。思路: 我们发现,以二进制的每一位为分界线,当在同一段的数大于等于三个的时候,它必然是可以变成无序的,并且只要操作一次,就是把大的两个数异或。而当其他情况时,我们发现由于数据的限制a<=10^9,

2020-12-02 20:38:05 959

原创 Educational Codeforces Round 99 (Rated for Div. 2)(详细题意+思路,A-D题)

A. Strange FunctionsLet’s define a function f(x) (x is a positive integer) as follows: write all digits of the decimal representation of x backwards, then get rid of the leading zeroes. For example, f(321)=123, f(120)=21, f(1000000)=1, f(111)=111.Let’s d

2020-12-02 20:30:38 257

原创 Codeforces Round #687 (Div. 2, based on Technocup 2021 Elimination Round 2)(详细题意+思路 A-C题)

A. Prison BreakThere is a prison that can be represented as a rectangular matrix with n rows and m columns. Therefore, there are n⋅m prison cells. There are also n⋅m prisoners, one in each prison cell. Let’s denote the cell in the i-th row and the j-th co

2020-11-29 18:16:32 3793

原创 武汉大学2020年新生程序设计竞赛(同步赛)——F 仓鼠的完美算术教室

武汉大学2020年新生程序设计竞赛(同步赛)——F 仓鼠的完美算术教室思路: 因为他让你求所有不重复的数,我们正常求就使10^12次复杂度,肯定会超时,这时我们考虑道用前缀和来求。那具体怎么用前缀和呢,我们发现,我们从前往后遍历,当遍历道2时,2的次方数,比如4,8……都会和2有重合的地方,我们只要找到有多少不重复的就行了。比如说n=10,m=20,那么我们就有2,4,8是有可能连续的,而且有三个,我们预先处理出来在这个m次的情况下连续1个到连续20个最多有可能有多少种情况,为什么我们只用算到20,因为2

2020-11-24 21:08:05 265

原创 Codeforces Round #685 (Div. 2)——D Circle Game(思维+模拟+对称博弈)

Codeforces Round #685 (Div. 2)——D Circle GameUtkarsh is forced to play yet another one of Ashish’s games. The game progresses turn by turn and as usual, Ashish moves first.Consider the 2D plane. There is a token which is initially at (0,0). In one move

2020-11-22 15:25:18 202 2

原创 北京信息科技大学第十二届程序设计竞赛暨ACM选拔赛(同步赛)题解

A 爱丽丝的人偶(一)思路: 先排小的,然后插空排大的就好了。#include<bits/stdc++.h>using namespace std;typedef long long ll;const ll maxn=0x3f3f3f3f;int a[1000007];int main(){ int n; cin>>n; int e; if(n%2==0){ e=n/2; }else{ e=n/2+1; } int cnt=1; for(

2020-11-21 18:20:18 1770 4

原创 Codeforces Round #683 (Div. 2, by Meet IT)——D. Catching Cheaters

Codeforces Round #683 (Div. 2, by Meet IT)——D. Catching CheatersYou are given two strings A and B representing essays of two students who are suspected cheaters. For any two strings C, D we define their similarity score S(C,D) as 4⋅LCS(C,D)−|C|−|D|, where

2020-11-16 18:35:40 100

原创 Codeforces Round #682 (Div. 2)——D. Powerful Ksenia

Codeforces Round #682 (Div. 2)——D. Powerful KseniaKsenia has an array a consisting of n positive integers a1,a2,…,an.In one operation she can do the following:choose three distinct indices i, j, k, and thenchange all of ai,aj,ak to ai⊕aj⊕ak simultaneou

2020-11-14 16:43:57 123

原创 Codeforces Round #682 (Div. 2)——C. Engineer Artem(思维)

Codeforces Round #682 (Div. 2)——C. Engineer ArtemArtem is building a new robot. He has a matrix a consisting of n rows and m columns. The cell located on the i-th row from the top and the j-th column from the left has a value ai,j written in it.If two ad

2020-11-14 16:39:57 128

原创 Hello 2020——B. New Year and Ascent Sequence

Hello 2020——B. New Year and Ascent SequenceA sequence a=[a1,a2,…,al] of length l has an ascent if there exists a pair of indices (i,j) such that 1≤i<j≤l and ai<aj. For example, the sequence [0,2,0,2,0] has an ascent because of the pair (1,4), but th

2020-11-12 17:01:51 132

原创 Hello 2020——G. Seollal

Hello 2020——G. SeollalRecall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also

2020-11-12 16:48:43 131

原创 Codeforces Round #611 (Div. 3)——F. DIY Garland

Codeforces Round #611 (Div. 3)——F. DIY GarlandPolycarp has decided to decorate his room because the New Year is soon. One of the main decorations that Polycarp will install is the garland he is going to solder himself.Simple garlands consisting of severa

2020-11-10 21:21:26 93

原创 Codeforces Round #678 (Div. 2)—— D. Bandit in a City(图论)

Codeforces Round #678 (Div. 2)—— D. Bandit in a CityBandits appeared in the city! One of them is trying to catch as many citizens as he can.The city consists of n squares connected by n−1 roads in such a way that it is possible to reach any square from a

2020-11-06 21:47:06 167

原创 Codeforces Round #681 (Div. 1, based on VK Cup 2019-2020 - Final)——B. Identify the Operations(思维+组合)

Codeforces Round #681 (Div. 1, based on VK Cup 2019-2020 - Final)——B. Identify the OperationsWe start with a permutation a1,a2,…,an and with an empty array b. We apply the following operation k times.On the i-th iteration, we select an index ti (1≤ti≤n−i

2020-11-06 20:21:36 152

原创 Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)——D. Extreme Subtraction

Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)——D. Extreme SubtractionYou are given an array a of n positive integers.You can use the following operation as many times as you like: select any integer 1≤k≤n and do one of two things:dec

2020-11-06 09:22:28 90

原创 Codeforces Round #607 (Div. 1)——C. Jeremy Bearimy

Codeforces Round #607 (Div. 1)——C. Jeremy BearimyWelcome! Everything is fine.You have arrived in The Medium Place, the place between The Good Place and The Bad Place. You are assigned a task that will either make people happier or torture them for eterni

2020-11-05 20:28:05 84

原创 Codeforces Round #607 (Div. 1)——A. Cut and Paste

Codeforces Round #607 (Div. 1)——A. Cut and PasteWe start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by si.There is one cursor. The cursor’s loc

2020-11-05 16:37:41 81

原创 Codeforces Round #607 (Div. 1)-B. Beingawesomeism

Codeforces Round #607 (Div. 1)-B. BeingawesomeismYou are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a r×c grid. Each cell on the grid represents a country. Each country h

2020-11-05 16:30:01 101

原创 Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)——C. The Delivery Dilemma(枚举)

Codeforces Round #681 (Div. 2, based on VK Cup 2019-2020 - Final)——C. The Delivery DilemmaPetya is preparing for his birthday. He decided that there would be n different dishes on the dinner table, numbered from 1 to n. Since Petya doesn’t like to cook, h

2020-11-03 22:48:58 149

原创 Educational Codeforces Round 79 (Rated for Div. 2)-D. Santa‘s Bot(求逆元+简单概率)

Educational Codeforces Round 79 (Rated for Div. 2)-D. Santa’s BotSanta Claus has received letters from n different kids throughout this year. Of course, each kid wants to get some presents from Santa: in particular, the i-th kid asked Santa to give them o

2020-11-03 22:38:41 267

原创 Codeforces Round #676 (Div. 2)-D. Hexagons(模拟)

Codeforces Round #676 (Div. 2)-D. HexagonsLindsey Buckingham told Stevie Nicks “Go your own way”. Nicks is now sad and wants to go away as quickly as possible, but she lives in a 2D hexagonal world.Consider a hexagonal tiling of the plane as on the pictu

2020-10-29 19:10:32 92

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除