https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1+s[1]+s1+...+s1+s[size-1]+s1+s[size]+s1\),求n个字符串依次相乘后最长连续字符相同的子序列长度 题解 鬼畜的题意 or 难以优化的复杂度,都需要观察性质才能做,第二串要插入第一个串每个字符之间,可以看出字符数增长的速度很快,所以并不能把整个字符存下来 只看一种…
Codeforces Round #579 (Div. 3) 传送门 A. Circle of Students 这题我是直接把正序.逆序的两种放在数组里面直接判断. Code #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 205; int q, n; int a[N], b[N], c[N]; int main() { ios::sync_with_stdio(false);…
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则,假如u在v相邻前面,那么u和v可以交换位置,问你是队列最后一个人的时候你最前可以换到前面哪里 题解 因为相邻才能换,所以最后一个换到前面一定是一步一步向前走,所以不存在还要向后走的情况 设最后一个为u,假设前面有一个能和u换位置的集合,那么需要将这些点尽量往后移动去接u 假设前面有一个不能和u换位置的集合S,…
#include<bits/stdc++.h>using namespace std;char s[200007],t[200007];int last[200007][27],nxt[200007][27];int l[200007],r[200007];int main(){ cin>>s+1>>t+1; int n=strlen(s+1); int m=strlen(t+1); for(int i=1;i<=n;++i){ for(int j=0;j<…
A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the s…
A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an eleva…
题意:给你一个模式串\(t\),现在要在主串\(s\)中删除多个子串,使得得到的\(s\)的子序列依然包含\(t\),问能删除的最长子串长度. 题解:首先,我们不难想到,我们可以选择\(s\)头部到最右边的子序列的头部和最左边的子序列的尾部到\(s\)的尾部这两个子串,除去这两个子串,我们要找的最大子串一定在子序列的头部到尾部中,即子序列中两个相邻字符位置的间隔,那么很显然,我们想让相邻的字符之间相隔最大,所以问题也就转化成了:求模式串的相邻字符在主串中的最大间隔长度,最优的情况一定是最左的子序…
思考之后再看题解,是与别人灵魂之间的沟通与碰撞 A. Circle of Students 题意 给出n个数,问它们向左或者向右是否都能成一个环.比如样例5是从1开始向左绕了一圈 [3, 2, 1, 5, 4] 变成 [1, 2, 3, 4, 5]; 思路 我的方法是差分,假如成立,相邻两个数的差的绝对值要么是1要么是n-1. #include<iostream> #include<cstdio> #include<algorithm> #include<cmat…
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(abs(i-j)<h[i]\),那么向j方向推倒i,j也会倒,问选择任意数量骨牌向任意方向推到,使得全部骨牌都倒下的代价最小 题解 连锁反应可以用单调栈或者链表模拟 定义dp[i]为推倒a[i,m]的最小代价 对于每个i,有两种选择: 向左推:\(dp[l[i]+1]=min(dp[l[i]+1],dp[…
A. 2Char time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most tw…
Arkady coordinates rounds on some not really famous competitive programming platform. Each round features nn problems of distinct difficulty, the difficulties are numbered from 11 to nn. To hold a round Arkady needs nn new (not used previously) probl…
题目链接:https://codeforces.com/contest/1203/problem/D2 题意: 给你S串.T串,问你最长删除多长的子串使得S串里仍然有T的子序列. 思路: 想了好久,先正着跑一下S串,记录T串每一个字符最左边在哪里,再倒着跑一下,记录T串的每一个字符最右边在哪里. 最后跑一下答案: 1. 开头和结尾特判一下,但不是max( L[1]-1 , l1-R[l2] ) , 而是对两个max( L[1]-1 , l1-L[l2]-1 ).max( R[1]-1 , l1-…
A. Circle of Students      题目:https://codeforces.com/contest/1203/problem/A 题意:一堆人坐成一个环,问能否按逆时针或者顺时针正好是 1-n的顺序 思路:水题,把数组开两倍,或者标记当前位置都可以 #include<bits/stdc++.h> #define maxn 100005 #define mod 1000000007 using namespace std; typedef long long ll; int…
比赛链接:https://codeforc.es/contest/1203/ A. Circle of Students 题意:\(T\)组询问,每组询问给出\(n\)个数字,问这\(n\)个数字能否围成圆环.(围成圆环指,从某一位开始顺时针或逆时针遍历,数组为\(1, 2, 3, ..., n\)) 分析:把数组复制一份,两个数组首尾相接,正反判定两次即可. AC代码: #include<bits/stdc++.h> #define SIZE 200010 #define rep(i, a,…
#include<bits/stdc++.h>using namespace std;string s[100007];set<int>st[100007][7];int t[207];int a[100007],b[100007][2],c[100007],d[100007][2];int main(){ t['a']=1; t['e']=2; t['i']=3; t['o']=4; t['u']=5; int n; cin>>n; for(int i=1;i<…
http://codeforces.com/contest/1203/problem/F1 Examples input 1 - - output 1 YES input 2 - - output 2 YES input 3 - - output 3 YES input 4 - output 4 NO Note In the first example, the possible order is: 1,2,3. In the second example, the possible order…
题意: 给你一个01字符串,现在你可以删除其中的一些子序列,要求如下:当遇到1 0的俩个连续子字符串后,可以删除其中的一个字符,现在要求把他删到尽量最短并且字典序最小,输出最后的字符串 题解: 刚开始想着就是模拟,谁知道越模拟越复杂,,,最后换思路一看,这不就是输出所有前缀0,输出所有后缀1.中间(中间就是去掉前缀0和后缀1之后的)如果有0的话就输出0就行了.如果前缀0加上后缀1刚好等于原字符串长度,就不用判断中间那一段了. 代码: 1 #include <stdio.h> 2 #includ…
C. Zebras time limit per test memory limit per test 512 megabytes input standard input output standard output Oleg writes down the history of the days he lived. For each day he decides if it was good or bad. Oleg calls a non-empty sequence of days a …
This morning, Roman woke up and opened the browser with nn opened tabs numbered from 11 to nn. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many ta…
#include<bits/stdc++.h>using namespace std;long long dp[107];int main(){    int cnt=1;    dp[1]=1;    for(int i=2;i<=1e9;i*=2){        dp[++cnt]=dp[cnt-1]*4+1;//记录长度为2^cnt的正方形最多能被切割的次数    }    //for(int i=1;dp[i]!=0;i++)        //printf("%ll…
构造边权,从0开始给边赋值,初始选取一条边权为0,每次赋值的贡献为这一条链两侧的结点(包含链的端点)个数之积,下一次赋值以当前链其一端点续一条边,边权为上次赋的值+1.先DFS找到点的组合这条链两侧结点的个数(包含链的端点),然后枚举端点进行DP. #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; vector<]; ][]; ][]; ][]; void dfs(long long now…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;vector<int>adj[100007];map<vector<int>,int>mp;int main(){ int n,m; scanf("%d%d",&n,&m); int u,v; for(int i=1;i<=m;++i){ scanf("%d%d&qu…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int a[27],b[27];int vis[9][9];int dis[9];int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m; cin>>n>>m; for(int i=1;i<=m;++i) cin>&…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;long long a[7007],b[7007];multiset<long long>st;int visit[7007];int main(){ int n; cin>>n; for(int i=1;i<=n;++i){ cin>>a[i]; st.insert(a[i]); } for(int i=1;i…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[100007];int main(){ cin>>s+1; int n=strlen(s+1); int cnt=0; for(int i=n;i>=1;--i){//从后向前,保证后面的解都是合法的情况下 if(s[i]=='1'){//如果当前位置的数字是1 if(cnt)//i后面1的个数小于0的个数,此时如果把i位…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;const int maxn=300;const int inf=1e9;long long a[100007];long long b[100007];int val[maxn + 1][maxn + 1]; // 原图的邻接矩阵inline int floyd(const int &n) { static int dis[maxn + 1][…
题意:有一堆石子,你每次可以选择相邻(就算两堆石子中间有很多空堆也不算)的两堆石子,使得两堆石子的个数同时\(-1\),你在刚开始的时候有一次交换相邻石子的机会,问你最后能否拿走所有石子. 题解:对于第一堆石子和最后一堆石子,它们只能靠第二堆石子和倒数第二堆石子减去才合法,所以我们由第一堆石子不断向右推和最后一堆石子不断向左推,这个过程可以用前缀和\(pre\)与后缀和\(suf\)表示.如果我们当前选择堆\(<i-1,i>\)的话,那么前缀和\(pre[i-2]\)和后缀和\(suf[i+1…
B Equal Rectangles 题意: 给你4*n个数,让你判断能不能用这个4*n个数为边凑成n个矩形,使的每个矩形面积相等 题解: 原本是想着用二分来找出来那个最终的面积,但是仔细想一想,那个面积只能是给出的4*n个数中的最小值和最大值的乘积,如果这两个长度不凑成一个矩形,那么肯定全部矩形的面积会出现不一致的 代码: 1 //The idea was to use dichotomies to find that area, and then use that area to figur…
题意:给你一组数,每个数都可以进行一次加一减一,问最后最多能有多少不同的数. 题解:我们可以用桶存每个数的次数,然后枚举\([1,150001]\)来求对答案的贡献,然后贪心,这里我们不用担心其他乱七八糟的东西,直接根据桶中的个数来求贡献即可,但是要先选\(i-1\)的情况,因为后面的数取不到\(i-1\),假如我们不选\(i-1\),而是选了\(i\)和\(i+1\),后面的数可能会冲突不能选,而\(i\)和\(i+1\)就没必要考虑选择顺序了,因为无论他们和后面的数冲不冲突,对答案的贡献都是…
题意:有两个数组\(a\)和\(b\),每次比较它们最左端的元素,取小的加入新的数组\(c\),若\(a\)或\(b\)其中一个为空,则将另一个全部加入\(c\),现在给你一个长度为\(2n\)的数组\(c\),问是否能有两个长度为\(n\)的数组\(a\)和\(b\)构成. 题解:我们从左向右看\(c\),记一个最大值\(mx\),观察样例不难发现,跟随在\(mx\)后面比\(mx\)小的元素,它们一定来自同一个数组,比如第三个样例: 3 2 6 1 5 7 8 4 \(3,2\)一定来自同一…