首页 > 其他分享 >Educational Codeforces Round 154 (Rated for Div. 2)

Educational Codeforces Round 154 (Rated for Div. 2)

时间:2023-09-02 20:11:22浏览次数:36  
标签:Educational Rated 154 int typedef long -- include define

Preface

太FW了现在,纯纯给队伍拖后腿,马上要成为我们队CF Rating最低的了

但换句话说徐神和祁神都这么猛,我直接躺着被嘎嘎带飞好像也很爽啊

不管怎么样还是要多练,不过接下来可能要按专题重点突破了,明天队里开个会确定下大家的主攻方向再说


A. Prime Deletion

因为\(13\)和\(31\)都是质数,因此判断这两个数的位置关系即可

#include<cstdio>
#include<iostream>
#include<utility>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<set>
#include<array>
#include<random>
#include<bitset>
#include<ctime>
#include<limits.h>
#include<assert.h>
#include<unordered_map>
#define RI register int
#define CI const int&
#define mp make_pair
#define fi first
#define se second
#define Tp template <typename T>
using namespace std;
typedef long long LL;
typedef long double LDB;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair <int,int> pi;
typedef vector <int> VI;
typedef array <int,3> tri;
const int N=15;
int t,pos[N]; char s[N];
int main()
{
	//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
	for (scanf("%d",&t);t;--t)
	{
		RI i; for (scanf("%s",s+1),i=1;i<=9;++i) pos[s[i]-'0']=i;
		if (pos[1]<pos[3]) puts("13"); else puts("31");
	}
	return 0;
}

B. Two Binary Strings

由于开头和结尾确定,因此我们可以枚举两个位置\(i,j\),当\(a_i=b_i=0\and a_j=b_j=1\and a_{[i+1,j-1]}=b_{[i+1,j-1]}\)时一定有解

当然其实可以直接枚举\(i,i+1\),比赛时候铸币了看数据范围就滚去写\(O(n^2)\)的了,没写\(O(n)\)

#include<cstdio>
#include<iostream>
#include<utility>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<set>
#include<array>
#include<random>
#include<bitset>
#include<ctime>
#include<limits.h>
#include<assert.h>
#include<unordered_map>
#define RI register int
#define CI const int&
#define mp make_pair
#define fi first
#define se second
#define Tp template <typename T>
using namespace std;
typedef long long LL;
typedef long double LDB;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair <int,int> pi;
typedef vector <int> VI;
typedef array <int,3> tri;
const int N=5005;
int t,n,f[N][N]; char a[N],b[N];
int main()
{
	//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
	for (scanf("%d",&t);t;--t)
	{
		RI i,j; scanf("%s%s",a+1,b+1); n=strlen(a+1);
		for (i=1;i<=n;++i) for (j=1;j<=n;++j) f[i][j]=0;
		for (i=1;i<=n;++i)
		{
			if (!(f[i][i]=a[i]==b[i])) continue;
			for (j=i+1;j<=n;++j)
			if (!(f[i][j]=a[j]==b[j])) break;
		}
		bool flag=0; for (i=1;i<=n;++i) for (j=i+1;j<=n;++j)
		if (a[i]=='0'&&b[i]=='0'&&a[j]=='1'&&b[j]=='1'&&(i+1<=j-1?f[i+1][j-1]:1)) flag=1;
		puts(flag?"YES":"NO");
	}
	return 0;
}

C. Queries for the Array

被C题狠狠地腐乳了,还是靠ztc教我才会的,被狠狠地克制了

考虑序列的形态形如这样,先是若干个已知的位置,然后是若干个未知的位置

当遇到0时就把未知的位置的最后一个改成不合法的标记,然后如果有添加操作就在后面再加上若干个未知的位置

然后就是分情况讨论清楚即可,应该有更简单的做法的说

#include<cstdio>
#include<iostream>
#include<utility>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<set>
#include<array>
#include<random>
#include<bitset>
#include<ctime>
#include<limits.h>
#include<assert.h>
#include<unordered_map>
#define RI register int
#define CI const int&
#define mp make_pair
#define fi first
#define se second
#define Tp template <typename T>
using namespace std;
typedef long long LL;
typedef long double LDB;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair <int,int> pi;
typedef vector <int> VI;
typedef array <int,3> tri;
const int N=200005;
int t,n,cnt; char s[N]; set <int> mx[2];
int main()
{
	//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
	for (scanf("%d",&t);t;--t)
	{
		RI i,j; scanf("%s",s+1); n=strlen(s+1);
		bool flag=1,sign=0; int known=0,unknown=0,len=0;
		for (i=1;i<=n&&flag;++i)
		{
			if (s[i]=='1')
			{
				if (sign) flag=0; known+=unknown; unknown=0;
			}
			if (s[i]=='0')
			{
				if (!sign)
				{
					if (!known&&unknown>1) sign=1,--unknown; else
					if (known>=1&&unknown>=1) sign=1,--unknown; else flag=0;
				}
			}
			if (s[i]=='+') sign?++len:++unknown;
			if (s[i]=='-')
			{
				if (len>0) --len; else
				if (sign) sign=0; else
				if (unknown>0) --unknown; else
				if (known>0) --known; else flag=0;
			}
		}
		puts(flag?"YES":"NO");
	}
	return 0;
}

D. Sorting By Multiplication

傻逼题,比C简单到不知道哪里去了

考虑如果不能乘负数就是把序列分成\(m\)段,每段内的元素都是单调递增的,最后答案就是\(m-1\),要使段数最小就直接贪心地划分即可

如果能乘负数也很简单,就是确定一个分界点后,后面部分划成单调递增的段,前面部分划成单调递减的段即可

#include<cstdio>
#include<iostream>
#include<utility>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<set>
#include<array>
#include<random>
#include<bitset>
#include<ctime>
#include<limits.h>
#include<assert.h>
#include<unordered_map>
#define RI register int
#define CI const int&
#define mp make_pair
#define fi first
#define se second
#define Tp template <typename T>
using namespace std;
typedef long long LL;
typedef long double LDB;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair <int,int> pi;
typedef vector <int> VI;
typedef array <int,3> tri;
const int N=200005;
int t,n,a[N],suf[N],pre[N];
int main()
{
	//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
	for (scanf("%d",&t);t;--t)
	{
		RI i; for (scanf("%d",&n),i=1;i<=n;++i) scanf("%d",&a[i]);
		for (suf[n]=1,i=n-1;i>=1;--i) suf[i]=suf[i+1]+(a[i]>=a[i+1]);
		for (pre[1]=1,i=2;i<=n;++i) pre[i]=pre[i-1]+(a[i-1]<=a[i]);
		int ans=min(suf[1]-1,pre[n]); for (i=2;i<=n;++i)
		ans=min(ans,pre[i-1]+suf[i]-1); printf("%d\n",ans);
	}
	return 0;
}

E. Non-Intersecting Subpermutations

ORZ祁神,比赛时候教了我怎么做,但我因为一个铸币下标写错了没调出来

考虑DP,设\(f_{i,j}\)表示做了前\(i\)个位置,从位置\(i\)往前的\(j\)个数互不相同的方案数,转移的话有以下情况:

  • \(f_{i,j}\times (k-j)\to f_{i+1,j+1}\)
  • \(f_{i,j}\to f_{i+1,s}\),其中\(s\in[1,j]\)

然后要计算答案的话由于题目要求区间不能相交,但我们贪心地每次一旦出现\(j=k\)的情况就直接计算它的贡献,\(f_{i,j}\times k^{n-i}\to ans\),然后注意转移变成\(k\to f_{i+1,1}\)即可

复杂度\(O(nk)\)

#include<cstdio>
#include<iostream>
#include<utility>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<set>
#include<array>
#include<random>
#include<bitset>
#include<ctime>
#include<limits.h>
#include<assert.h>
#include<unordered_map>
#define RI register int
#define CI const int&
#define mp make_pair
#define fi first
#define se second
#define Tp template <typename T>
using namespace std;
typedef long long LL;
typedef long double LDB;
typedef unsigned long long u64;
typedef __int128 i128;
typedef pair <int,int> pi;
typedef vector <int> VI;
typedef array <int,3> tri;
const int N=4005,mod=998244353;
int t,n,k,f[N][N],g[N][N],pw[N],ans;
inline void inc(int& x,CI y)
{
	if ((x+=y)>=mod) x-=mod;
}
int main()
{
	//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
	RI i,j; for (scanf("%d%d",&n,&k),pw[0]=i=1;i<=n;++i) pw[i]=1LL*pw[i-1]*k%mod;
	for (f[1][1]=k,i=1;i<=n;++i)
	{
		for (j=k-1;j>=1;--j) inc(g[i][j],g[i][j+1]);
		for (j=1;j<=k;++j) inc(f[i][j],g[i][j]);
		for (j=1;j<=k;++j)
		{
			if (j==k)
			{
				inc(ans,1LL*f[i][j]*pw[n-i]%mod);
				inc(f[i+1][1],1LL*f[i][j]*k%mod); continue;
			}
			inc(f[i+1][j+1],1LL*f[i][j]*(k-j)%mod);
			inc(g[i+1][j],f[i][j]);
		}
	}
	return printf("%d",ans),0;
}

Postscript

so weak……

标签:Educational,Rated,154,int,typedef,long,--,include,define
From: https://www.cnblogs.com/cjjsb/p/17674143.html

相关文章

  • Educational Codeforces Round 23 A - F
    EducationalCodeforcesRound23目录EducationalCodeforcesRound23A-TreasureHuntB-MakesAndTheProductC-ReallyBigNumbersD-ImbalancedArrayE-ChoosingTheCommanderF-MEXQueriesA-TreasureHunt往四个方向走,每次操作会变动横坐标和纵坐标,横纵坐标......
  • Educational Codeforces Round 154 (Rated for Div. 2)(A—C)
    A.PrimeDeletion思路:从1到9,每个数后面都可以加一个数构成一个含有两个数的质数,只需要从s[1]~s[9]中找到一个数与s[0]构成质数即可代码实现/*******************************|Author:CHC|Problem:A.PrimeDeletion|Contest:Codeforces-EducationalCodeforcesR......
  • 【题解】Educational Codeforces Round 153(CF1860)
    每次打都想感叹一句,Educational名不虚传。A.NotaSubstring题目描述:有\(t\)组数据,对于每一组数据,你需要判断能否构造一个只由左右括号组成且长度为已经给定字符串的\(2\)倍且已经给定的字符串不是子串的合法字符串。注:合法的字符串是左右括号能完全匹配的字符串。如果能,......
  • Educational Codeforces Round 113
    稳定发挥4题A题文件输出没去掉WA了一发B题特殊情况没判到,WA了好几发,中间还交到D题去了C题简单判断一下无解,然后组合数求一下就行D题其实也挺简单的,考虑严格夹在两条竖线之间的点(不包括边界),如果它们不是在同一水平线上,则必然大于Manhattan距离,而且两个点对之间要么是x方向走多......
  • Educational Codeforces Round 154 (Rated for Div. 2)
    感觉edu的题目都比较有新意;A.PrimeDeletion题意:给定长度为9的数,且1-9每个数字出现一次,求按照原定顺序选几个数组成的质数(起码选择两个);下意识写了一个dfs,过了;1#include<bits/stdc++.h>2usingnamespacestd;3intread(){4charch=getchar();intx=0,f=1;5......
  • Educational Codeforces Round 123
    A.DoorsandKeys#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvoidsolve(){strings;cin>>s;map<char,int>pos;for(inti=0;i<6;i++)pos[s[i]]=i;if(pos['r&......
  • Educational Codeforces Round 15 A - E
    EducationalCodeforcesRound15目录EducationalCodeforcesRound15A-MaximumIncreaseB-PowersofTwoC-CellularNetworkD-RoadtoPostOfficeE.AnalysisofPathesinFunctionalGraphA-MaximumIncrease一段上升子数组\([l,r]\)最大化\(r-l+1\),我们......
  • Educational Codeforces Round 5 A-E
    EducationalCodeforcesRound5垫底咯,中间老师找我去聊了下新学期的机房借用和训练,但出去前就只有我没出E目录EducationalCodeforcesRound5AComparingTwoLongIntegersBDinnerwithEmmaCTheLabyrinthDLongestk-GoodSegmentE-SumofRemaindersAComparingTwo......
  • TO-277封装肖特基二极管SP1545L:15A 45V
    目前,市面上供应肖特基二极管的厂家、供应商特别地多,更多选择的背后,带来的却是更多的迷茫和不知所措。采购肖特基二极管,哪家好呢?提及“东沃电子DOWOSEMI”这个国产二极管品牌,很多客户可能第一想到他家的TVS二极管、ESD二极管、稳压二极、压敏电阻MOV、陶瓷气体放电管GDT、自恢复保险......
  • 【CF1542C】Strange Function(数论)
    题目大意:#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constllmod=1e9+7;lln;lllcm(llx,lly){ returnx/__gcd(x,y)*y;}intmain(){ intT; cin>>T; while(T--){ cin>>n; llans=n%mod; for(lli=1,j=1;n/j......