Loading

CSP 后多校四

这场考试确实很让我想吐槽,个人认为是一套很垃圾的 \(NOIP\) 模拟赛.

\(T1\)\(T3\) 傻了吧唧地给了两道水题,一个半小时 \(A\) 完了,\(T2\) 一个大模拟题面给得不清楚直接弃了,\(T4\) 特意整一个斯特林数凸显这场考试有多么地 \(NOIP\).

总的来说这场考试个人感觉没啥意义,做得没有什么收获就很难受.

A. 特殊字符串

签到题,随便写.

A_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS{
	#define ll long long
	#define lf double
	#define ull unsigned ll
	#define pb push_back
	#define mp make_pair
	#define lb lower_bound
	#define ub upper_bound
	#define lbt(x) ((x)&(-(x)))
	#define Fill(x,y) memset(x,y,sizeof(x))
	#define Copy(x,y) memcpy(x,y,sizeof(x))
	#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
	auto read=[]()->ll{
		ll w=0; bool cit=1; char ch;
		while(!isdigit(ch=getchar())) if(ch=='-') cit=0;
		while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar();
		return cit?w:(-w);
	};
} using namespace BSS;

const ll N=1e5+21;

char ch[N];

ll m,n,ans;
ll dp[30],val[N];
ll ic[30][30];
signed main(){
	File(shiki);
	n=read(),scanf("%s",ch+1);
	for(ll i=1;i<=n;i++) val[i]=ch[i]-'a'+1;
	m=read(); ll u,v; Fill(dp,-0x3f);
	for(ll i=1;i<=m;i++){
		scanf("%s",ch+1),u=ch[1]-'a'+1;
		scanf("%s",ch+1),v=ch[1]-'a'+1;
		ic[u][v]+=read();
	}
	for(ll i=1;i<=n;i++){
		u=val[i]; if(ic[u][u]) dp[u]+=ic[u][u];
		for(ll j=1;j<=26;j++){
			if(u==j) continue;
			dp[u]=max(dp[u],dp[j]+ic[j][u]);
		}
		dp[u]=max(dp[u],0ll);
	}
	for(ll i=1;i<=26;i++) ans=max(ans,dp[i]);
	printf("%lld\n",ans),exit(0);
}

B. 宝可梦

大模拟,找准顺序就行了.

B_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS{
	#define ll long long
	#define lf double
	#define ull unsigned ll
	#define pb push_back
	#define kap make_pair
	#define lb lower_bound
	#define ub upper_bound
	#define lbt(x) ((x)&(-(x)))
	#define Fill(x,y) memset(x,y,sizeof(x))
	#define Copy(x,y) memcpy(x,y,sizeof(x))
	#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
	auto read=[]()->ll{
		ll w=0; bool cit=1; char ch;
		while(!isdigit(ch=getchar())) if(ch=='-') cit=0;
		while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar();
		return cit?w:(-w);
	};
} using namespace BSS;

const ll N=4e6+21,inf=1e15;

char ch[N];

ll m,n,sx,sy,ex,ey,nx,ny,cnt,ans,ops;
ll rk[N];
ll dx[4]={0,-1,0,1},dy[4]={1,0,-1,0};
vector<ll> mt[N]; 
map<char,int> dir;
auto getid=[](ll x,ll y,ll d)->ll{ return (x-1)*m*4+(y-1)*4+d; };
void solve(ll x,ll y,ll d){
	for(ll di=(d+3)%4;;(++di)%=4){
		nx=x+dx[di],ny=y+dy[di];
		if(nx<1 or nx>n or ny<1 or ny>m) continue;
		if(!mt[nx][ny]) continue;
		if(!rk[getid(x,y,di)]) rk[getid(x,y,di)]=++cnt,solve(nx,ny,di);
		break;
	}
}
auto Work=[]()->void{
	ll d,x,y,sx,sy,ex,ey,id,ans=inf;
	sx=read(),sy=read(),ex=read(),ey=read(),scanf("%s",ch+1),d=dir[ch[1]];
	if(sx==ex and sy==ey) { puts("0"); return ; }
	for(ll i=0;i<4;i++){
		id=rk[getid(ex,ey,i)];
		if(!id) continue;
		// cout<<id<<' '<<rk[getid(sx,sy,d)]<<endl;
		if(id>=rk[getid(sx,sy,d)]) ans=min(ans,id-rk[getid(sx,sy,d)]);
		else ans=min(ans,id-rk[getid(sx,sy,d)]+cnt);
	}
	printf("%lld\n",ans);
};
signed main(){
	File(pokemon);
	n=read(),m=read(); ll flag=1;
	for(ll i=1;i<=n;i++){
		mt[i].pb(0),scanf("%s",ch+1);
		for(ll j=1;j<=m;j++) mt[i].pb(ch[j]=='.' ? 1 : 0);
	}
	dir['R']=0,dir['U']=1,dir['L']=2,dir['D']=3;
	for(ll i=1;flag and i<=n;i++){
		for(ll j=1;flag and j<=m;j++) 
			if(mt[i][j]) solve(i,j,3),flag=0;
	}
	for(int Ts=read();Ts;Ts--) Work();
	exit(0);
}

C. 矩阵

签到题,随便写.

C_code
#include<bits/stdc++.h>
using namespace std;
namespace BSS{
	#define ll long long
	#define lf double
	#define ull unsigned ll
	#define pb push_back
	#define mp make_pair
	#define lb lower_bound
	#define ub upper_bound
	#define lbt(x) ((x)&(-(x)))
	#define Fill(x,y) memset(x,y,sizeof(x))
	#define Copy(x,y) memcpy(x,y,sizeof(x))
	#define File(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
	auto read=[]()->ll{
		ll w=0; bool cit=1; char ch;
		while(!isdigit(ch=getchar())) if(ch=='-') cit=0;
		while(isdigit(ch)) w=(w<<3)+(w<<1)+(ch^48),ch=getchar();
		return cit?w:(-w);
	};
} using namespace BSS;

const ll N=1e6+21,inf=1e15;

ll m,n,ts,ans,cnt,tot;
ll in[N],bin[N],dis[N],vis[N];
vector<ll> to[N],mat[N];
struct I { ll x,y,w; } p[N];
struct II { ll u,v,w; } e[N<<4],o[N<<4];
struct III{
	ll id,d;
	III(){}
	III(ll id,ll d) : id(id),d(d) {}
	friend bool operator < (III i,III j){
		return i.d>j.d; 
	}
};
priority_queue<III> que;
auto getid=[](ll x,ll y)->ll{ return (x-1)*m+y; };
auto add=[](ll u,ll v,ll w)->void{
	e[++ts].u=u,e[ts].v=v,e[ts].w=w;
};
auto bfs=[]()->void{
	ll u;
	for(ll i=1;i<=tot;i++){
		dis[u=bin[i]]=-inf,vis[u]=0;
		if(!in[u]) que.push(III(u,0)),dis[u]=1;
	}
	while(que.size()){
		u=que.top().id,que.pop();
		if(vis[u]) continue; vis[u]=1;
		for(auto v : to[u]){
			if(dis[v]<dis[u]+1){
				que.push(III(v,dis[v]=dis[u]+1));
			}
		}
	}
	for(ll i=1;i<=tot;i++){
		ans=max(ans,dis[bin[i]]);
		to[bin[i]].clear(),vis[bin[i]]=0;
	}
};
signed main(){
	File(matrix);
	n=read(),m=read(); ll u,v;
	for(ll i=1;i<=n;i++){
		mat[i].pb(0);
		for(ll j=1;j<=m;j++) mat[i].pb(read());
	}
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=m;j++){
			p[++cnt].x=i,p[cnt].y=j,p[cnt].w=mat[i][j];
			if(i>1 and mat[i][j]%mat[i-1][j]==0){
				if(mat[i][j]==mat[i-1][j]) puts("-1"),exit(0);
				if(mat[i][j]/mat[i-1][j]>200) ans=max(ans,2ll);
				else add(getid(i-1,j),cnt,mat[i][j]/mat[i-1][j]);
			}
			if(j>1 and mat[i][j]%mat[i][j-1]==0){
				if(mat[i][j]==mat[i][j-1]) puts("-1"),exit(0);
				if(mat[i][j]/mat[i][j-1]>200) ans=max(ans,2ll);
				else add(getid(i,j-1),cnt,mat[i][j]/mat[i][j-1]);
			}
			if(i<n and mat[i][j]%mat[i+1][j]==0){
				if(mat[i][j]==mat[i+1][j]) puts("-1"),exit(0);
				if(mat[i][j]/mat[i+1][j]>200) ans=max(ans,2ll);
				else add(getid(i+1,j),cnt,mat[i][j]/mat[i+1][j]);
			}
			if(j<m and mat[i][j]%mat[i][j+1]==0){
				if(mat[i][j]==mat[i][j+1]) puts("-1"),exit(0);
				if(mat[i][j]/mat[i][j+1]>200) ans=max(ans,2ll);
				else add(getid(i,j+1),cnt,mat[i][j]/mat[i][j+1]);
			}
		}
	}
	sort(e+1,e+1+ts,[](II i,II j){ return i.w<j.w; });
	for(ll i=1,j=1;i<=200;i++){
		while(e[j].w==i){
			u=e[j].u,v=e[j].v,to[u].pb(v),in[v]++;
			bin[++tot]=u,bin[++tot]=v,j++;
		}
		bfs();
	}
	printf("%lld\n",max(ans,1ll)),exit(0);
}

D. 乘法

斯特林数,先鸽.

posted @ 2021-10-30 21:40  AaMuXiiiiii  阅读(44)  评论(0编辑  收藏  举报